XGitUrl: https://git.xiph.org/?p=opus.git;a=blobdiff_plain;f=doc%2Fdraftietfcodecopus.xml;h=bd01b6771d5a36b4ffd0dd8a41869b41d4c3738e;hp=4b6c03a1a82e85f1f49a8dbc749e6135d90e8604;hb=1a1736526d1421b682418c47801d967f2bdd0a70;hpb=905fa5ba04b512c23f239549c28b9432cd5a63f6
diff git a/doc/draftietfcodecopus.xml b/doc/draftietfcodecopus.xml
index 4b6c03a1..bd01b677 100644
 a/doc/draftietfcodecopus.xml
+++ b/doc/draftietfcodecopus.xml
@@ 1,8 +1,8 @@

+

+
Definition of the Opus Audio Codec
@@ 19,7 +19,7 @@
Canada
+1 514 2828858
jeanmarc.valin@octasic.com
+jmvalin@jmvalin.ca
@@ 38,8 +38,22 @@
+
+Mozilla Corporation
+
+
+650 Castro Street
+Mountain View
+CA
+94041
+USA
+
++1 650 9030800
+tterriberry@mozilla.com
+
+

+
General
@@ 47,8 +61,8 @@
This document describes the Opus codec, designed for interactive speech and audio
transmission over the Internet.
+This document defines the Opus codec, designed for interactive speech and audio
+ transmission over the Internet.
@@ 57,205 +71,607 @@ transmission over the Internet.
We propose the Opus codec based on a linear prediction layer (LP) and an
MDCTbased enhancement layer. The main idea behind the proposal is that
the speech low frequencies are usually more efficiently coded using
linear prediction codecs (such as CELP variants), while the higher frequencies
are more efficiently coded in the transform domain (e.g. MDCT). For low
sampling rates, the MDCT layer is not useful and only the LPbased layer is
used. On the other hand, nonspeech signals are not always adequately coded
using linear prediction, so for music only the MDCTbased layer is used.
+The Opus codec is a realtime interactive audio codec composed of a linear
+ prediction (LP)based layer and a Modified Discrete Cosine Transform
+ (MDCT)based layer.
+The main idea behind using two layers is that in speech, linear prediction
+ techniques (such as 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, by combining them, achieve better quality than either
+ one individually.
In this proposed prototype, the LP layer is based on the
SILK codec
 and the MDCT layer is based on the
CELT codec
 .
+The primary normative part of this specification is provided by the source code
+ in .
+In general, only the decoder portion of this software is normative, though a
+ significant amount of code is shared by both the encoder and decoder.
+
+The decoder contains significant amounts of integer and fixedpoint arithmetic
+ which must be performed exactly, including all rounding considerations, so any
+ useful specification must make extensive use of domainspecific 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 humanreadable symbolic representations for machine
+behavior.
+For these reasons this RFC uses the reference implementation as the sole
+ symbolic representation of the codec.
This is a work in progress.



+
+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 English 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 multiplication in the text.
+In general, the text is focused on the "what" and "why" while the symbolic
+representation most clearly provides the "how".
+
+
In hybrid mode, each frame is coded first by the LP layer and then by the MDCT
layer. In the current prototype, the cutoff frequency is 8 kHz. In the MDCT
layer, all bands below 8 kHz are discarded, such that there is no coding
redundancy between the two layers. Also both layers use the same instance of
the range coder to encode the signal, which ensures that no "padding bits" are
wasted. The hybrid approach makes it easy to support both constant bitrate
(CBR) and varaible bitrate (VBR) coding. Although the SILK layer used is VBR,
it is easy to make the bit allocation of the CELT layer produce a final stream
that is CBR by using all the bits left unused by the SILK layer.
+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.
+
+
+Even when using floatingpoint, various operations in the codec require
+ bitexact fixedpoint behavior.
+The notation "Qn ", where
+ n is an integer, denotes the number of binary
+ digits to the right of the decimal point in a fixedpoint number.
+For example, a signed Q14 value in a 16bit 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.
+E.g., the text will explicitly indicate any shifts required after a
+ multiplication.

In addition to their frame size, the SILK and CELT codecs require
a lookahead of 5.2 ms and 2.5 ms, respectively. SILK's lookahead is due to
noise shaping estimation (5 ms) and the internal resampling (0.2 ms), while
CELT's lookahead is due to the overlapping MDCT windows. To compensate for the
difference, the CELT encoder input is delayed by 2.7 ms. This ensures that low
frequencies and high frequencies arrive at the same time.
+Expressions, where included in the text, follow C operator rules and
+ precedence, with the exception that syntax like "2**n" is used to indicate 2
+ raised to the power n.
+The text also makes use of the following functions:
+
+
+The smallest of two values x and y.
+
+

+
The source code is currently available in a
Git repository
which references two other
repositories (for SILK and CELT). Development snapshots are provided at
.
+The largest of two values x and y.
+
+
+
+
+
+
+
+With this definition, if lo>hi, the lower bound is the one that is enforced.
+
+
+The sign of x, i.e.,
+
+ 0 .
+]]>
+
+

+
There are three possible operating modes for the proposed prototype:

A linear prediction (LP) mode for use in low bitrate connections with up to 8 kHz audio bandwidth (16 kHz sampling rate)
A hybrid (LP+MDCT) mode for fullbandwidth speech at medium bitrates
An MDCTonly mode for very low delay speech transmission as well as music transmission.

Each of these modes supports a number of difference frame sizes and sampling
rates. In order to distinguish between the various modes and configurations,
we define a singlebyte tableofcontents (TOC) header that can used in the transport layer
(e.g RTP) to signal this information. The following describes the proposed
TOC byte.
+The basetwo logarithm of f.
+
+
The LP mode supports the following configurations (numbered from 0 to 11):
+The minimum number of bits required to store a positive integer n in two's
+ complement notation, or 0 for a nonpositive integer n.
+
+ 0
+]]>
+
+Examples:
8 kHz: 10, 20, 40, 60 ms (0..3)
12 kHz: 10, 20, 40, 60 ms (4..7)
16 kHz: 10, 20, 40, 60 ms (8..11)
+ilog(1) = 0
+ilog(0) = 0
+ilog(1) = 1
+ilog(2) = 2
+ilog(3) = 2
+ilog(4) = 3
+ilog(7) = 3
for a total of 12 configurations.
+
+
+
+
+
+
+
+
+
+
+The Opus codec scales from 6 kb/s narrowband mono speech to 510 kb/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.
+Internally, the codec always operates at a 48 kHz sampling rate, though it
+ allows input and output of various bandwidths, defined as follows:
+
+
+Abbreviation
+Audio Bandwidth
+Sampling Rate (Effective)
+NB (narrowband) 4 kHz 8 kHz
+MB (mediumband) 6 kHz 12 kHz
+WB (wideband) 8 kHz 16 kHz
+SWB (superwideband) 12 kHz 24 kHz
+FB (fullband) 20 kHz 48 kHz
+
+
+These 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.
The hybrid mode supports the following configurations (numbered from 12 to 15):

32 kHz: 10, 20 ms (12..13)
48 kHz: 10, 20 ms (14..15)

for a total of 4 configurations.
+The LP layer is based on the
+ SILK codec
+ .
+It supports NB, MB, or WB audio and frame sizes from 10 ms to 60 ms,
+ and requires an additional 5.2 ms lookahead for noise shaping estimation
+ (5 ms) and internal resampling (0.2 ms).
+Like Vorbis and many other modern codecs, SILK is inherently designed for
+ variablebitrate (VBR) coding, though an encoder can with sufficient effort
+ produce constantbitrate (CBR) or nearCBR streams.
The MDCTonly mode supports the following configurations (numbered from 16 to 31):

8 kHz: 2.5, 5, 10, 20 ms (16..19)
16 kHz: 2.5, 5, 10, 20 ms (20..23)
32 kHz: 2.5, 5, 10, 20 ms (24..27)
48 kHz: 2.5, 5, 10, 20 ms (28..31)
+The MDCT layer is based on the
+ CELT codec
+ .
+It supports sampling NB, WB, SWB, or FB audio and frame sizes from 2.5 ms
+ to 20 ms, and requires an additional 2.5 ms lookahead 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 perframe 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, nonspeech signals are not always adequately coded using
+ linear prediction, so for music only the MDCT layer should be used.
+
+
+
+A hybrid mode allows the use of both layers simultaneously with a frame size of
+ 10 or 20 ms and a SWB or FB audio bandwidth.
+Each frame is split into a low frequency signal and a high frequency signal,
+ with a cutoff of 8 kHz.
+The LP layer then codes the low frequency signal, followed by the MDCT layer
+ coding the high frequency signal.
+In the MDCT layer, all bands below 8 kHz are discarded, so there is no
+ coding redundancy between the two layers.
+
+
+
+At the decoder, the two decoder outputs are simply added together.
+To compensate for the different lookaheads 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 lookahead for noise
+ shaping or using a simpler resampler in the LP layer, but this will reduce
+ quality.
+However, the base 2.5 ms lookahead 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.
+
+
+
+
+
+
+As described, the two layers can be combined in three possible operating modes:
+
+A LPonly mode for use in low bitrate connections with an audio bandwidth of
+ WB or less,
+A hybrid (LP+MDCT) mode for SWB or FB speech at medium bitrates, and
+An MDCTonly mode for very low delay speech transmission as well as music
+ transmission.
for a total of 16 configurations.
+A single packet may contain multiple audio frames, however they must share a
+ common set of parameters, including the operating mode, audio bandwidth, frame
+ size, and channel count.
+A singlebyte tableofcontents (TOC) header signals which of the various modes
+ and configurations a given packet uses.
+It is composed of a frame count code, "c", a stereo flag, "s", and a
+ configuration number, "config", arranged as illustrated in
+ .
+A description of each of these fields follows.
+
+
+
+
+
+
+
+The top five bits of the TOC byte, labeled "config", encode one of 32 possible
+ configurations of operating mode, audio bandwidth, and frame size.
+ lists the parameters for each configuration.
+
+Configuration Number(s)
+Mode
+Bandwidth
+Frame Size(s)
+0...3 LPonly NB 10, 20, 40, 60 ms
+4...7 LPonly MB 10, 20, 40, 60 ms
+8...11 LPonly WB 10, 20, 40, 60 ms
+12...13 Hybrid SWB 10, 20 ms
+14...15 Hybrid FB 10, 20 ms
+16...19 MDCTonly NB 2.5, 5, 10, 20 ms
+20...23 MDCTonly WB 2.5, 5, 10, 20 ms
+24...27 MDCTonly SWB 2.5, 5, 10, 20 ms
+28...31 MDCTonly FB 2.5, 5, 10, 20 ms
+
There is thus a total of 32 configurations, encoded in 5 bits. On bit is used to signal mono vs stereo, which leaves 2 bits for the number of frames per packets (codes 0 to 3):
+One additional bit, labeled "s", is used to signal mono vs. stereo, with 0
+ indicating mono and 1 indicating stereo.
+The remaining two bits, labeled "c", code the number of frames per packet
+ (codes 0 to 3) as follows:
0: 1 frames in the packet
+0: 1 frame in the packet
1: 2 frames in the packet, each with equal compressed size
2: 2 frames in the packet, with different compressed size
3: arbitrary number of frames in the packet
+2: 2 frames in the packet, with different compressed sizes
+3: an arbitrary number of frames in the packet
For code 2, the TOC byte is followed by the length of the first frame, encoded as described below.
For code 3, the TOC byte is followed by a byte encoding the number of frames in the packet, with the MSB indicating VBR. In the VBR case, the byte indicating the number of frames is followed by N1 frame
lengths encoded as described below. As an additional limit, the audio duration contained
within a packet may not exceed 120 ms.
The compressed size of the frames (if needed) is indicated  usually  with one byte, with the following meaning:
+A wellformed Opus packet MUST contain at least one byte with the TOC
+ information, though the frame(s) within a packet MAY be zero bytes long.
+It must also obey various additional rules indicated by "MUST", "MUST NOT",
+ etc., in this section.
+A receiver MUST NOT process packets which violate these rules as normal Opus
+ packets.
+They are reserved for future applications, such as inband headers (containing
+ metadata, etc.) or multichannel support.
+
+
+
+When a packet contains multiple VBR frames, 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:
0: No frame (DTX or lost packet)
1251: Size of the frame in bytes
252255: A second byte is needed. The total size is (size[1]*4)+size[0]
+
+1...251: Size of the frame in bytes
+252...255: A second byte is needed. The total size is (size[1]*4)+size[0]
The maximum size representable is 255*4+255=1275 bytes. For 20 ms frames, that
represents a bitrate of 510 kb/s, which is really the highest rate anyone would want
to use in stereo mode (beyond that point, lossless codecs would be more appropriate).
+The maximum representable size is 255*4+255=1275 bytes.
+For 20 ms frames, this represents a bitrate of 510 kb/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.

Simplest case: one narrowband mono 20ms SILK frame
+No length is transmitted for the last frame in a VBR packet, or 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, it MUST NOT exceed 1275 bytes, to allow for repacketization by
+ gateways, conference bridges, or other software.

.
+
+
+

Two 48 kHz mono 5 ms CELT frames of the same compressed size:
+For code 1 packets, the TOC byte is immediately followed by the
+ (N1)/2 bytes of compressed data for the first frame, followed by
+ (N1)/2 bytes of compressed data for the second frame, as illustrated in
+ .
+The number of payload bytes available for compressed data, N1, MUST be even
+ for all code 1 packets.
+
+
+

.
+The length of the first frame, N1, MUST be no larger than the size of the
+ payload remaining after decoding that length for all code 2 packets.
+
+
+
+
+
+For code 3 packets, the TOC byte is followed by a byte encoding the number of
+ frames in the packet in bits 0 to 5 (marked "M" in the figure below), with bit
+ 6 indicating whether or not padding is inserted (marked "p" in the figure
+ below), and bit 7 indicating VBR (marked "v" in the figure below).
+M MUST NOT be zero, and the audio duration contained within a packet MUST NOT
+ exceed 120 ms.
+This limits the maximum frame count for any frame size to 48 (for 2.5 ms
+ frames), with lower limits for longer frame sizes.
+ illustrates the layout of the frame count
+ byte.
+
+
+
+
+
+When 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 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.
+The additional padding bytes appear at the end of the packet, and SHOULD be set
+ to zero by the encoder, however the decoder MUST accept any value for the
+ padding bytes.
+By using code 255 multiple times, it is possible to create a packet of any
+ specific, desired size.
+Let P be the total amount of padding, including both the trailing padding bytes
+ themselves and the header bytes used to indicate how many there are.
+Then P MUST be no more than N2 for CBR packets, or NM1 for VBR packets.
+
+
+In the CBR case, the compressed length of each frame in bytes is equal to the
+ number of remaining bytes in the packet after subtracting the (optional)
+ padding, (N2P), divided by M.
+This number MUST be an integer multiple of M.
+The compressed data for all M frames then follows, each of size
+ (N2P)/M bytes, as illustrated in .
+
+
+
+
Two 48 kHz mono 20ms hybrid frames of different compressed size:
+In the VBR case, the (optional) padding length is followed by M1 frame
+ lengths (indicated by "N1" to "N[M1]" in the figure below), each encoded in a
+ one or two byte sequence as described above.
+The packet MUST contain enough data for the M1 lengths after 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.
+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 .
+The number of header bytes (TOC byte, frame count byte, padding length bytes,
+ and frame length bytes), plus the length of the first M1 frames themselves,
+ plus the length of the padding MUST be no larger than N, the total size of the
+ packet.
+
+
+
+
+
+Simplest case, one NB mono 20 ms SILK frame:
+
+

Four 48 kHz stereo 20ms CELT frame of the same compressed size:

+Two FB mono 5 ms CELT frames of the same compressed size:
+
+
+
+
+Two FB mono 20 ms hybrid frames of different compressed size:
+
+
+
+
+Four FB stereo 20 ms CELT frames of the same compressed size:
+
+
+
+
@@ 263,11 +679,12 @@ Four 48 kHz stereo 20ms CELT frame of the same compressed size:
The Opus decoder consists of two main blocks: the SILK decoder and the CELT decoder.
+The Opus decoder consists of two main blocks: the SILK decoder and the CELT decoder.
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 as illustrated in the
block diagram below. At any given time, one or both of the SILK and CELT decoders
may be active.
+may be active.
+
+
+
+
+Opus uses an entropy coder based on ,
+which is itself a rediscovery of the FIFO arithmetic code introduced by .
+It is very similar to arithmetic encoding, except that encoding is done with
+digits in any base instead of with bits,
+so it is faster when using larger bases (i.e., an octet). All of the
+calculations in the range coder must use bitexact 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.
+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.
+
+
+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.
+Opus only uses static contexts.
+They are not adapted to the statistics of the data as it is coded.
+
+
+The parameters needed to encode or decode a symbol in a given context are
+ represented by a threetuple (fl,fh,ft), with
+ 0 <= fl < fh <= ft <= 65535.
+The values of this tuple are derived from the probability model for the
+ symbol, represented by traditional frequency counts
+ (although, since Opus uses static contexts, these are not updated as symbols
+ are decoded).
+Let f[i] be the frequency of the i th symbol in a
+ context with n symbols total.
+Then the threetuple corresponding to the k th
+ symbol is given by
+
+
+
+
+
+The range decoder extracts the symbols and integers encoded using the range
+ encoder in .
+The range decoder maintains an internal state vector composed of the twotuple
+ (val,rng), representing the difference between the high end of the current
+ range and the actual coded value, minus one, and the size of the current
+ range, respectively.
+Both val and rng are 32bit unsigned integer values.
+The decoder initializes rng to 128 and initializes val to 127 minus the top 7
+ bits of the first input octet.
+It then immediately normalizes the range using the procedure described in
+ .
+
+
+
+
+Decoding a symbol is a twostep process.
+The first step determines a 16bit 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 threetuple (fl,fh,ft)
+ corresponding to that symbol.
+
+
+The first step is implemented by ec_decode() (entdec.c), which computes
+ fs = ft  min(val/(rng/ft)+1, ft).
+The divisions here are exact integer division.
+
+
+The decoder then identifies the symbol in the current context corresponding to
+ fs; i.e., the one whose threetuple (fl,fh,ft) satisfies fl <= fs < fh.
+It uses this tuple to update val according to
+ val = val  (rng/ft)*(ftfh).
+If fl is greater than zero, then the decoder updates rng using
+ rng = (rng/ft)*(fhfl).
+Otherwise, it updates rng using rng = rng  (rng/ft)*(ftfh).
+After these updates, implemented by ec_dec_update() (entdec.c), it normalizes
+ the range using the procedure in the next section, and returns the index of
+ the identified symbol.
+
+
+With this formulation, all the truncation error from using finite precision
+ arithmetic accumulates in symbol 0.
+This makes the cost of coding a 0 slightly smaller, on average, than the
+ negative log of its estimated probability 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.
+
+
+
+
+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 8 bits of input into sym, using the remaining bit from
+ the previous input octet as the high bit of sym, and the top 7 bits of the
+ next octet as the remaining bits of sym.
+If no more input octets remain, it uses zero bits instead.
+Then, it sets val to (val<<8)+(255sym)&0x7FFFFFFF.
+
+
+It is normal and expected that the range decoder will read several bytes
+ into the raw bits data (if any) at the end of the packet by the time the frame
+ is completely decoded, as illustrated in .
+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 decoder
+ will decode the intended values regardless of the data contained in the raw
+ bits.
+ 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.
+
+
+
+  :
++++++++++++++++++++++++++++++++++
+ ^ ^
+  End of data buffered by the range coder 
+...+
+ 
+  End of data consumed by raw bits
+ +...
+]]>
+
+
+
+
+
+
+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.
+
+
+
+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 avoids one of the divisions.
+
+
+
+
+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 base2 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
+ fl = 0, fh = (1<<logp)1, ft = (1<<logp) if the returned value
+ of fs is less than (1<<logp)1 (a "0" was decoded), and with
+ fl = (1<<logp)1, fh = ft = (1<<logp) otherwise (a "1" was
+ decoded).
+The implementation requires no multiplications or divisions.
+
+
+
+
+The last is ec_dec_icdf() (entdec.c), which decodes a single symbol with a
+ tablebased 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 for the kth symbol in
+ the context, which is equal to (1<<ftb)fl for the (k+1)st symbol.
+fl for the 0th symbol is assumed to be 0, and the table is terminated by a
+ value of 0 (where fh == 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 = (1<<ftb)icdf[k1] (or 0 if k == 0),
+ fh = (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 8bit 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 draft 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 zeroprobability values and adding the
+ constant offset of the first value with a nonzero probability to its return
+ value.
+
+
+
+
+
+
+The raw bits used by the CELT layer are packed at the end of the packet, with
+ the least significant bit of the first value to be packed in the least
+ significant bit of the last byte, filling up to the most significant bit in
+ the last byte, and 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 , 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.
+
+
+
+
+
+The ec_dec_uint() (entdec.c) function decodes one of ft equiprobable values in
+ the range 0 to ft1, inclusive, each with a frequency of 1, where ft may be as
+ large as 2**321.
+Because ec_decode() is limited to a total frequency of 2**161, this is split
+ up into a range coded symbol representing up to 8 of the high bits of the
+ value, and, if necessary, raw bits representing the remaining bits.
+The limit of 8 bits in the range coded symbol is a tradeoff 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 ft1, 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
+ ft1, inclusive.
+Let ftb = ilog(ft1), i.e., the number of bits required to store ft1 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 threetuple (t,t+1,ft).
+
+
+If ftb is greater than 8, then the top 8 bits of t are decoded using
+ t = ec_decode((ft1>>ftb8)+1),
+ the decoder state is updated using the threetuple
+ (t,t+1,(ft1>>ftb8)+1), and the remaining bits are decoded as raw bits,
+ setting t = t<<ftb8ec_dec_bits(ftb8).
+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 and/or report to the application that a problem has occurred.
+
+
+
+
+
+
+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 wholebit
+ 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 bitexact
+ manner, and 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 worstcase cost of
+ p 1/8th bits may actually advance the return value of ec_tell_frac() by
+ p1, 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 symbol that requires a whole number of bits (i.e., ft/(fhfl) is a power
+ of two, including values of ft larger than 2**8 with ec_dec_uint()), and there
+ are at least p 1/8th bits available, decoding the symbol will never advance
+ the decoder past the end of the frame, i.e., will never
+ bust the budget.
+Frames contain a whole number of bits, and the return value of ec_tell_frac()
+ will only advance by more than p 1/8th bits in this case if there was a
+ fractional number of bits remaining, and by no more than the fractional part.
+However, when p is not a whole number of bits, an extra 1/8th bit is required
+ to ensure decoding the symbol will not bust.
+
+
+The reference implementation keeps track of the total number of whole bits that
+ have been processed by the decoder so far in a 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 33 just after the initial range renormalization
+ process completes (or equivalently, it can be initialized to 9 before 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.
+
+
+
+
+The whole number of bits buffered in rng may be estimated via l = ilog(rng).
+ec_tell() then becomes a simple matter of removing these bits from the total.
+It returns (nbits_total  l).
+
+
+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.
+
+
+
+
+
+ec_tell_frac() estimates the number of bits buffered in rng to fractional
+ precision.
+Since rng must be greater than 2**23 after renormalization, l must be at least
+ 24.
+Let r = rng>>(l16), so that 32768 <= r < 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 l.
+First, update r = r*r>>15.
+Then add the 16th bit of r to l via l = 2*l + (r>>16).
+Finally, if this bit was a 1, reduce r by a factor of two via r = r>>1,
+ so that it once again lies in the range 32768 <= r < 65536.
+
+
+This procedure is repeated three times to extend l to 1/8th bit precision.
+ec_tell_frac() then returns (nbits_total*8  l).
+
+
+
+
+
+
+
+
+
+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
+ longterm and shortterm prediction synthesis filters.
+It runs in NB, MB, and WB modes internally.
+When used in a hybrid frame in SWB or FB mode, the LP layer itself still only
+ runs in WB mode.
+
+
+Internally, the LP layer of a single Opus frame is composed of either a single
+ 10 ms SILK frame or between one and three 20 ms SILK frames.
+Each SILK frame is in turn composed of either two or four 5 ms subframes.
+Optional Low BitRate Redundancy (LBRR) frames, which are reducedbitrate
+ encodings of previous SILK frames, may appear 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, and from here on this draft
+ will use "SILK frame" to refer to either one and "regular SILK frame" if it
+ needs to draw a distinction between the two.
+
+
+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 midside 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 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.
+
+
+
+Symbol(s)
+PDF
+Condition
+VAD flags {1, 1}/2
+LBRR flag {1, 1}/2
+Perframe LBRR flags
+Frame Type
+Gain index
+
+Order of the symbols in the SILK section of the bitstream.
+
+
+
+
+
+An overview of the decoder is given in .
+
+
+
+ Range > Decode +
+ 1  Decoder  2  Parameters + 5 
+ ++ ++ 4  
+ 3   
+ \/ \/ \/
+ ++ ++ ++
+  Generate > LTP > LPC >
+  Excitation   Synthesis   Synthesis  6
+ ++ ++ ++
+
+1: Range encoded bitstream
+2: Coded parameters
+3: Pulses and gains
+4: Pitch lags and LTP coefficients
+5: LPC coefficients
+6: Decoded signal
+]]>
+
+Decoder block diagram.
+
+
+
+
+ The range decoder decodes the encoded parameters from the received bitstream. Output from this function includes the pulses and gains for the excitation signal generation, as well as LTP and LSF codebook indices, which are needed for decoding LTP and LPC coefficients needed for LTP and LPC synthesis filtering the excitation signal, respectively.
+
+
+
+
+
+ Pulses and gains are decoded from the parameters that were decoded by the range decoder.
+
+
+
+ When a voiced frame is decoded and LTP codebook selection and indices are received, LTP coefficients are decoded using the selected codebook by choosing the vector that corresponds to the given codebook index in that codebook. This is done for each of the four subframes.
+ The LPC coefficients are decoded from the LSF codebook by first adding the chosen LSF vector and the decoded LSF residual signal. The resulting LSF vector is stabilized using the same method that was used in the encoder, see
+ . The LSF coefficients are then converted to LPC coefficients, and passed on to the LPC synthesis filter.
+
+
+
+
+
+ The pulses signal is multiplied with the quantization gain to create the excitation signal.
+
+
+
+
+
+ For voiced speech, the excitation signal e(n) is input to an LTP synthesis filter that will recreate the long term correlation that was removed in the LTP analysis filter and generate an LPC excitation signal e_LPC(n), according to
+
+
+
+
+
+ using the pitch lag L, and the decoded LTP coefficients b_i.
+ The number of LTP coefficients is 5, and thus d = 2.
+
+ For unvoiced speech, the output signal is simply a copy of the excitation signal, i.e., e_LPC(n) = e(n).
+
+
+
+
+
+ In a similar manner, the shortterm correlation that was removed in the LPC analysis filter is recreated in the LPC synthesis filter. The LPC excitation signal e_LPC(n) is filtered using the LTP coefficients a_i, according to
+
+
+
+
+
+ where d_LPC is the LPC synthesis filter order, and y(n) is the decoded output signal.
+
+
+
+
+
+
+
+
+The LP layer begins with two to eight header bits, decoded in silk_Decode()
+ (silk_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 flags correspond to the mid channel, and a second
+ set of flags is included for the side channel.
+
+
+Because these are the first symbols decoded by the range coder, they can be
+ extracted directly from the upper 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.
+
+
+
+
+
+For Opus frames longer than 20 ms, a set of perframe LBRR flags is
+ decoded for each channel that has its LBRR flag set.
+For 40 ms Opus frames the 2frame LBRR flag PDF from
+ is used, and for 60 ms Opus frames
+ the 3frame LBRR flag PDF is used.
+For each channel, the resulting 2 or 3bit 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
+
+
+
+LBRR frames do not include their own separate VAD flags.
+An LBRR frame is only meant to be transmitted for active speech, thus all LBRR
+ frames are treated as active.
+
+
+
+
+
+Each SILK frame includes a set of side information that encodes the frame type,
+ quantization type and gains, shortterm prediction filter coefficients, LSF
+ interpolation weight, longterm prediction filter lags and gains, and a
+ pseudorandom number generator (PRNG) seed.
+This is followed by the quantized excitation signal.
+
+
+
+Each SILK frame begins with 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 the value either 0 or 1 and is decoded using the first PDF in
+ .
+If the frame is an LBRR frame or a regular SILK frame whose VAD flag was set
+ (an active frame), then the symbol ranges from 2
+ to 5, inclusive, and is decoded using the second PDF in
+ .
+ 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
+
+
+
+Frame Type
+Signal Type
+Quantization Offset Type
+0 Inactive 0
+1 Inactive 1
+2 Unvoiced 0
+3 Unvoiced 1
+4 Voiced 0
+5 Voiced 1
+
+
+
+
+
+
+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 the pitch gains 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.
+
+
+For the first LBRR frame, an LBRR frame where the previous LBRR frame was not
+ coded, or the first regular SILK frame in an Opus frame, the first subframe
+ uses an independent coding method.
+The 3 most significant bits of the quantization gain are decoded using a PDF
+ selected from based on the
+ decoded signal type.
+
+
+
+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
+
+
+
+The 3 least significant bits are decoded using a uniform PDF:
+
+
+PDF
+{32, 32, 32, 32, 32, 32, 32, 32}/256
+
+
+
+For all other subframes (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.
+The PDF in yields a delta gain index
+ 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
+
+
+The following formula translates this index into a quantization gain for the
+ current subframe using the gain from the previous subframe:
+
+
+
+
+
+silk_gains_dequant() (silk_gain_quant.c) dequantizes the gain for the
+ k th subframe and converts it into a linear Q16
+ scale factor via
+
+
+>16) + 2090)
+]]>
+
+
+The function silk_log2lin() (silk_log2lin.c) computes an approximation of
+ 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, if i < 16, then
+
+>16)+f)>>7)*(1<
+
+ yields the approximate exponential.
+Otherwise, silk_log2lin uses
+
+>16)+f)*((1<>7) .
+]]>
+
+
+
+
+
+
+
+Normalized Line Spectral Frequencies (LSFs) follow the quantization gains in
+ the bitstream, and represent the Linear Prediction Coefficients (LPCs) for the
+ current SILK frame.
+Once decoded, they form an increasing list of Q15 values between 0 and 1.
+These represent the interleaved zeros on the unit circle between 0 and pi
+ (hence "normalized") in the standard decomposition of the LPC filter into a
+ symmetric part and an antisymmetric part (P and Q in
+ ).
+Because of nonlinear effects in the decoding process, an implementation SHOULD
+ match the fixedpoint arithmetic described in this section exactly.
+An encoder SHOULD also use the same process.
+
+
+The normalized LSFs are coded using a twostage vector quantizer (VQ).
+NB and MB frames use an order10 predictor, while WB frames use an order16
+ predictor, and thus have different sets of tables.
+The first VQ stage uses a 32element codebook, coded with one of the PDFs in
+ , depending on the audio bandwidth and
+ the signal type of the current SILK frame.
+This yields a single index, I1 , for the entire
+ frame.
+This indexes an element in a coarse codebook, selects the PDFs for the
+ second stage of the VQ, and selects the prediction weights used to remove
+ intraframe redundancy from the second stage.
+The actual codebook elements are listed in
+ and
+ , but they are not needed until the last
+ stages of reconstructing the LSF coefficients.
+
+
+
+Audio Bandwidth
+Signal Type
+PDF
+NB or MB Inactive or unvoiced
+
+{44, 34, 30, 19, 21, 12, 11, 3,
+ 3, 2, 16, 2, 2, 1, 5, 2,
+ 1, 3, 3, 1, 1, 2, 2, 2,
+ 3, 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 or unvoiced
+
+{31, 21, 3, 17, 1, 8, 17, 4,
+ 1, 18, 16, 4, 2, 3, 1, 10,
+ 1, 3, 16, 11, 16, 2, 2, 3,
+ 2, 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
+
+
+
+
+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
+ , and the 8 (i...p) for WB frames
+ given in .
+Which PDF is used for which coefficient is driven by the index, I1,
+ decoded in the first stage.
+ lists the letter of the
+ corresponding PDF for each normalized LSF coefficient for NB and MB, and
+ lists the same information for WB.
+
+
+
+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
+
+
+
+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
+
+
+
+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
+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
+
+
+
+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
+j0
+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
+
+
+
+Decoding the second stage residual proceeds as follows.
+For each coefficient, the decoder reads a symbol using the PDF corresponding to
+ I1 from either or
+ , and subtracts 4 from the result
+ to given 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
+ , 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
+
+
+
+The decoded indices from both stages are translated back into normalized LSF
+ coefficients in silk_NLSF_decode() (silk_NLSF_decode.c).
+The stage2 indices represent residuals after both the first stage of the VQ
+ and a separate backwardsprediction 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.
+ 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.
+
+
+
+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
+
+
+
+The prediction is undone using the procedure implemented in
+ silk_NLSF_residual_dequant() (silk_NLSF_decode.c), which is as follows.
+Each coefficient selects its prediction weight from one of the two lists based
+ on the stage1 index, I1.
+ gives the selections for each
+ coefficient for NB and MB, and 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_LPC1.
+Then, the stage2 residual for each coefficient is computed via
+
+>8 : 0)
+ + ((((I2[k]<<10) + sign(I2[k])*102)*qstep)>>16) ,
+]]>
+
+ 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
+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
+A 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
+
+
+
+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 D C C C C C C C C C C C C C
+ 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
+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
+
+
+
+The spectral distortion introduced by the quantization of each LSF coefficient
+ varies, so the stage2 residual is weighted accordingly, using the
+ lowcomplexity weighting function proposed in .
+The weights are derived directly from the stage1 codebook vector.
+Let cb1_Q8[k] be the k th entry of the stage1
+ codebook vector from or
+ .
+Then for 0 <= k < d_LPC the following expression
+ computes the square of the weight as a Q18 value:
+
+
+
+
+
+ where cb1_Q8[1] = 0 and cb1_Q8[d_LPC] = 256, and the
+ division is exact integer division.
+This is reduced to an unsquared, Q9 value using the following squareroot
+ approximation:
+
+>(i8)) & 127
+y = ((i&1) ? 32768 : 46214) >> ((32i)>>1)
+w_Q9[k] = y + ((213*f*y)>>16)
+]]>
+
+The cb1_Q8[] vector completely determines these weights, and they may be
+ tabulated and stored as 13bit unsigned values (with a range of 1819 to 5227)
+ to avoid computing them when decoding.
+The reference implementation computes them on the fly in
+ silk_NLSF_VQ_weights_laroia() (silk_NLSF_VQ_weights_laroia.c) and its
+ caller, to reduce the amount of ROM required.
+
+
+
+I1
+Codebook
+
+ 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
+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
+
+
+
+I1
+Codebook
+
+ 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
+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
+
+
+
+Given the stage1 codebook entry cb1_Q8[], the stage2 residual res_Q10[], and
+ their corresponding weights, w_Q9[], the reconstructed normalized LSF
+ coefficients are
+
+
+
+ where the division is exact integer division.
+However, nothing thus far in the reconstruction process, nor in the
+ quantization process in the encoder, guarantees that the coefficients are
+ monotonically increasing and separated well enough to ensure a stable filter.
+When using the reference encoder, roughly 2% of frames violate this constraint.
+The next section describes a stabilization procedure used to make these
+ guarantees.
+
+
+
+
+The normalized LSF stabilization procedure is implemented in
+ silk_NLSF_stabilize() (silk_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).
+ gives the minimum spacings for NB and MB
+ and those for WB, where row k is the minimum allowed value of
+ NLSF_Q[k]NLSF_Q[k1].
+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.
+
+
+
+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
+
+
+
+The procedure starts off by trying to make small adjustments which attempt to
+ minimize the amount of distortion introduced.
+After 20 such adjustments, it falls back to a more direct method which
+ guarantees the constraints are enforced but may require large adjustments.
+
+
+Let NDeltaMin_Q15[k] be the minimum required spacing for the current audio
+ bandwidth from .
+First, the procedure finds the index i where
+ NLSF_Q15[i]  NLSF_Q15[i1]  NDeltaMin_Q15[i] is the
+ smallest, breaking ties by using the lower value of i.
+If this value is nonnegative, 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_LPC1] to
+ (32768  NDeltaMin_Q15[d_LPC]).
+For all other values of i, both NLSF_Q15[i1] and NLSF_Q15[i] are updated as
+ follows:
+
+>1) + \ NDeltaMin[k]
+ /_
+ k=0
+ d_LPC
+ __
+ max_center_Q15 = 32768  (NDeltaMin[i]>>1)  \ NDeltaMin[k]
+ /_
+ k=i+1
+center_freq_Q15 = clamp(min_center_Q15[i],
+ (NLSF_Q15[i1] + NLSF_Q15[i] + 1)>>1,
+ max_center_Q15[i])
+
+ NLSF_Q15[i1] = center_freq_Q15  (NDeltaMin_Q15[i]>>1)
+
+ NLSF_Q15[i] = NLSF_Q15[i1] + NDeltaMin_Q15[i] .
+]]>
+
+Then the procedure repeats again, until it has executed 20 times, or until
+ it stops because the coefficients satisfy all the constraints.
+
+
+After the 20th repetition of the above, 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_LPC1, NLSF_Q15[k] is set to
+
+
+
+Next, for each value of k from d_LPC1 down to 0, NLSF_Q15[k] is set to
+
+
+
+
+
+
+
+
+
+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 previous frame and the current frame.
+A Q2 interpolation factor follows the LSF coefficient indices in the bitstream,
+ which is decoded using the PDF in .
+This happens in silk_decode_indices() (silk_decode_indices.c).
+For the first frame after a decoder reset, when no prior LSF coefficients are
+ available, 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
+
+
+
+Let n2_Q15[k] be the normalized LSF coefficients decoded by the procedure in
+ , 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
+
+> 2) .
+]]>
+
+This interpolation is performed in silk_decode_parameters()
+ (silk_decode_parameters.c).
+
+
+
+
+
+Any LPC filter A(z) can be split into a symmetric part P(z) and an
+ antisymmetric part Q(z) such that
+
+
+
+with
+
+
+
+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
+
+
+
+
+
+However, SILK performs this reconstruction using a fixedpoint approximation so
+ that all decoders can reproduce it in a bitexact manner to avoid prediction
+ drift.
+The function silk_NLSF2A() (silk_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 true the inverse of the cosine function, when deriving the
+ normalized LSF coefficients.
+
+
+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 approximated cosine, c_Q17[k], is
+
+> 4 ,
+]]>
+
+ where cos_Q13[i] is the corresponding entry of
+ .
+
+
+
+
+0
+1
+2
+3
+0
+ 8192 8190 8182 8170
+4
+ 8152 8130 8104 8072
+8
+ 8034 7994 7946 7896
+12
+ 7840 7778 7714 7644
+16
+ 7568 7490 7406 7318
+20
+ 7226 7128 7026 6922
+24
+ 6812 6698 6580 6458
+28
+ 6332 6204 6070 5934
+32
+ 5792 5648 5502 5352
+36
+ 5198 5040 4880 4718
+40
+ 4552 4382 4212 4038
+44
+ 3862 3684 3502 3320
+48
+ 3136 2948 2760 2570
+52
+ 2378 2186 1990 1794
+56
+ 1598 1400 1202 1002
+60
+ 802 602 402 202
+64
+ 0 202 402 602
+68
+ 802 1002 1202 1400
+72
+1598 1794 1990 2186
+76
+2378 2570 2760 2948
+80
+3136 3320 3502 3684
+84
+3862 4038 4212 4382
+88
+4552 4718 4880 5040
+92
+5198 5352 5502 5648
+96
+5792 5934 6070 6204
+100
+6332 6458 6580 6698
+104
+6812 6922 7026 7128
+108
+7226 7318 7406 7490
+112
+7568 7644 7714 7778
+116
+7840 7896 7946 7994
+120
+8034 8072 8104 8130
+124
+8152 8170 8182 8190
+128
+8192
+
+
+
+Given the list of cosine values, silk_NLSF2A_find_poly() (silk_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,
+
+>16) ,
+
+q_Q16[k][j] = q_Q16[k1][j] + q_Q16[k1][j2]
+  ((c_Q17[2*k+1]*q_Q16[k1][j1] + 32768)>>16) .
+]]>
+
+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 32bit version of the LPC filter (without the leading 1.0
+ coefficient), a32_Q17[k], 0 <= k < d2:
+
+
+
+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.
+
+
+
+
+
+The a32_Q17[] coefficients are too large to fit in a 16bit value, which
+ significantly increases the cost of applying this filter in fixedpoint
+ 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 floatingpoint 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 the largest, breaking ties by using the lower value of k.
+Then, it computes the corresponding Q12 precision value, maxabs_Q12, subject to
+ an upper bound to avoid overflow in subsequent computations:
+
+> 5, 163838) .
+]]>
+
+If this is larger than 32767, the procedure derives the chirp factor,
+ sc_Q16[0], to use in the bandwidth expansion as
+
+> 2
+]]>
+
+ where the division here is exact 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.
+
+
+silk_bwexpander_32() (silk_bwexpander_32.c) peforms the bandwidth expansion
+ (again, only when maxabs_Q12 is greater than 32767) using the following
+ recurrence:
+
+> 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 32bit overflow using signed multiplication, but is otherwise
+ equivalent.
+
+
+After 10 rounds of bandwidth expansion are performed, they are simply saturated
+ to 16 bits:
+
+> 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 of the
+ coefficients still overflow a 16bit integer.
+This saturation is not performed if maxabs_Q12 drops to 32767 or less prior to
+ the 10th round.
+

+
The range decoder extracts the symbols and integers encoded using the range encoder in
 . The range decoder maintains an internal
state vector composed of the twotuple (dif,rng), representing the
difference between the high end of the current range and the actual
coded value, and the size of the current range, respectively. Both
dif and rng are 32bit unsigned integer values. rng is initialized to
2^7. dif is initialized to rng minus the top 7 bits of the first
input octet. Then the range is immediately normalized, using the
procedure described in the following section.
+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 18 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 LPC_inverse_pred_gain_QA() (silk_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_LPC1][n] = a[n], and then updated via
+
+
+


 Decoding symbols is a twostep process. The first step determines
 a value fs that lies within the range of some symbol in the current
 context. The second step updates the range decoder state with the
 threetuple (fl,fh,ft) corresponding to that symbol, as defined in
 .
+However, LPC_inverse_pred_gain_QA() approximates this using fixedpoint
+ arithmetic to guarantee reproducible results across platforms and
+ implementations.
+It is important to run on the real Q12 coefficients that will be used during
+ reconstruction, because small changes in the coefficients can make a stable
+ filter unstable, but increasing the precision back to Q16 allows more accurate
+ computation of the reflection coefficients.
+Thus, let
+
+> 5) << 4
+]]>
+
+ be the Q16 representation of the Q12 version of the LPC coefficients that will
+ eventually be used.
+Then for each k from d_LPC1 down to 0, if
+ abs(a32_Q16[k][k]) > 65520, the filter is unstable and the
+ recurrence stops.
+Otherwise, the row k1 of a32_Q16 is computed from row k as
+
+> 32) ,
+
+ b1[k] = ilog(div_Q30[k])  16 ,
+
+ (1<<29)  1
+ inv_Qb1[k] =  ,
+ div_Q30[k] >> (b1[k]+1)
+
+ err_Q29[k] = (1<<29)
+  ((div_Q30[k]<<(15b1[k]))*inv_Qb1[k] >> 16) ,
+
+ mul_Q16[k] = ((inv_Qb1[k] << 16)
+ + (err_Q29[k]*inv_Qb1[k] >> 13)) >> b1[k] ,
+
+ b2[k] = ilog(mul_Q16[k])  15 ,
+
+ t_Q16[k1][n] = a32_Q16[k][n]
+  ((a32_Q16[k][kn1]*rc_Q31[k] >> 32) << 1) ,
+
+a32_Q16[k1][n] = ((t_Q16[k1][n] *
+ (mul_Q16[k] << (16b2[k]))) >> 32) << b2[k] .
+]]>
+
+Here, rc_Q30[k] are the reflection coefficients.
+div_Q30[k] is the denominator for each iteration, and mul_Q16[k] is its
+ multiplicative inverse.
+inv_Qb1[k], which ranges from 16384 to 32767, is a lowprecision version of
+ that inverse (with b1[k] fractional bits, where b1[k] ranges from 3 to 14).
+err_Q29[k] is the residual error, ranging from 32392 to 32763, which is used
+ to improve the accuracy.
+t_Q16[k1][n], 0 <= n < k, are the numerators for the
+ next row of coefficients in the recursion, and a32_Q16[k1][n] is the final
+ version of that row.
+Every multiply in this procedure except the one used to compute mul_Q16[k]
+ requires more than 32 bits of precision, 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_Q16[k][k]) <= 65520 for
+ 0 <= k < d_LPC, then the filter is considerd stable.
 The first step is implemented by ec_decode()
 (rangedec.c),
 and computes fs = ftmin((dif1)/(rng/ft)+1,ft), where ft is
 the sum of the frequency counts in the current context, as described
 in . The divisions here are exact integer division.
+On round i, 1 <= i <= 18, if the filter passes this
+ stability check, then this procedure stops, and the final LPC coefficients to
+ use for reconstruction are
+
+> 5 .
+]]>
+
+Otherwise, a round of bandwidth expansion is applied using the same procedure
+ as in , with
+
+
+
+If, after the 18th round, the filter still fails the stability check, then
+ a_Q12[k] is set to 0 for all k.
+
+
+
+
+
 In the reference implementation, a special version of ec_decode()
 called ec_decode_bin() (rangeenc.c) is defined using
 the parameter ftb instead of ft. It is mathematically equivalent to
 calling ec_decode() with ft = (1<<ftb), but avoids one of the
 divisions.
+After the normalized LSF indices and, for 20 ms frames, the LSF
+ interpolation index, voiced frames (see )
+ include additional LongTerm Prediction (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.
+
+
 The decoder then identifies the symbol in the current context
 corresponding to fs; i.e., the one whose threetuple (fl,fh,ft)
 satisfies fl <= fs < fh. This tuple is used to update the decoder
 state according to dif = dif  (rng/ft)*(ftfh), and if fl is greater
 than zero, rng = (rng/ft)*(fhfl), or otherwise rng = rng  (rng/ft)*(ftfh). After this update, the range is normalized.
+The primary lag index is coded either relative to the primary lag of the prior
+ frame or as an absolute index.
+Like the quantization gains, the first LBRR frame, an LBRR frame where the
+ previous LBRR frame was not coded, or the first regular SILK frame in an Opus
+ frame all code the pitch lag as an absolute index.
+When the prior frame was not voiced, this also forces absolute coding.
 To normalize the range, the following process is repeated until
 rng > 2^23. First, rng is set to (rng<8)&0xFFFFFFFF. Then the next
 8 bits of input are read into sym, using the remaining bit from the
 previous input octet as the high bit of sym, and the top 7 bits of the
 next octet for the remaining bits of sym. If no more input octets
 remain, zero bits are used instead. Then, dif is set to
 (dif<<8)sym&0xFFFFFFFF (i.e., using wraparound if the subtraction
 overflows a 32bit register). Finally, if dif is larger than 2^31,
 dif is then set to dif  2^31. This process is carried out by
 ec_dec_normalize() (rangedec.c).
+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 reads the high
+ part using the 32entry codebook in
+ and the low part using the codebook corresponding to the current audio
+ bandwidth from .
+The final primary pitch lag is then
+
+
+
+ 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
+ , 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
+
+
+
+Audio Bandwidth
+PDF
+Scale
+Minimum Lag
+Maximum Lag
+NB {64, 64, 64, 64}/256 4 16 144
+MB {43, 42, 43, 43, 42, 43}/256 6 24 216
+WB {32, 32, 32, 32, 32, 32, 32, 32}/256 8 32 288
+
+
 Functions ec_dec_uint() or ec_dec_bits() are based on ec_decode() and
 decode one of N equiprobable symbols, each with a frequency of 1,
 where N may be as large as 2^321. Because ec_decode() is limited to
 a total frequency of 2^161, this is done by decoding a series of
 symbols in smaller contexts.


 ec_dec_bits() (entdec.c) is defined, like
 ec_decode_bin(), to take a single parameter ftb, with ftb < 32.
 and ftb < 32, and produces an ftbbit decoded integer value, t,
 initialized to zero. While ftb is greater than 8, it decodes the next
 8 most significant bits of the integer, s = ec_decode_bin(8), updates
 the decoder state with the 3tuple (s,s+1,256), adds those bits to
 the current value of t, t = t<<8  s, and subtracts 8 from ftb. Then
 it decodes the remaining bits of the integer, s = ec_decode_bin(ftb),
 updates the decoder state with the 3 tuple (s,s+1,1<<ftb), and adds
 those bits to the final values of t, t = t<<ftb  s.


 ec_dec_uint() (entdec.c) takes a single parameter,
 ft, which is not necessarily a power of two, and returns an integer,
 t, with a value between 0 and ft1, inclusive, which is initialized to zero. Let
 ftb be the location of the highest 1 bit in the two'scomplement
 representation of (ft1), or 1 if no bits are set. If ftb>8, then
 the top 8 bits of t are decoded using t = ec_decode((ft1>>ftb8)+1),
 the decoder state is updated with the threetuple
 (s,s+1,(ft1>>ftb8)+1), and the remaining bits are decoded with
 t = t<<ftb8ec_dec_bits(ftb8). If, at this point, t >= ft, then
 the current frame is corrupt, and decoding should stop. If the
 original value of ftb was not greater than 8, then t is decoded with
 t = ec_decode(ft), and the decoder state is updated with the
 threetuple (t,t+1,ft).
+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 21entry PDF in
+ .
+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
+
+
+
+ where lag_prev is the primary pitch lag from the previous frame and
+ delta_lag_index is the value just decoded.
+This allows a perframe 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
+
+
 The bit allocation routines in CELT need to be able to determine a
 conservative upper bound on the number of bits that have been used
 to decode from the current frame thus far. This drives allocation
 decisions which must match those made in the encoder. This is
 computed in the reference implementation to fractional bit precision
 by the function ec_dec_tell() (rangedec.c). Like all
 operations in the range decoder, it must be implemented in a
 bitexact manner, and must produce exactly the same value returned by
 ec_enc_tell() after encoding the same symbols.
+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
+ depending on the current frame size
+ and audio bandwidth.
+ through
+ give the corresponding offsets
+ to apply to the primary pitch lag for each subframe given the decoded codebook
+ index.


+
+Audio Bandwidth
+SILK Frame Size
+PDF
+NB 10 ms
+{143, 50, 63}/256
+NB 20 ms
+{68, 12, 21, 17, 19, 22, 30, 24,
+ 17, 16, 10}/256
+MB or WB 10 ms
+{91, 46, 39, 19, 14, 12, 8, 7,
+ 6, 5, 5, 4}/256
+MB or WB 20 ms
+{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}
+


 At the receiving end, the received packets are by the range decoder split into a number of frames contained in the packet. Each of which contains the necessary information to reconstruct a 20 ms frame of the output signal.



 An overview of the decoder is given in .


  Range > Decode +
 1  Decoder  2  Parameters + 5 
 ++ ++ 4  
 3   
 \/ \/ \/
 ++ ++ ++
  Generate > LTP > LPC >
  Excitation   Synthesis   Synthesis  6
 ++ ++ ++
+
+Index
+Subframe Offsets
+0 0, 0
+1 1, 0
+2 0, 1
+
1: Range encoded bitstream
2: Coded parameters
3: Pulses and gains
4: Pitch lags and LTP coefficients
5: LPC coefficients
6: Decoded signal
]]>

 Decoder block diagram.


+
+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
+


 The range decoder decodes the encoded parameters from the received bitstream. Output from this function includes the pulses and gains for the excitation signal generation, as well as LTP and LSF codebook indices, which are needed for decoding LTP and LPC coefficients needed for LTP and LPC synthesis filtering the excitation signal, respectively.


+
+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
+


 Pulses and gains are decoded from the parameters that was decoded by the range decoder.

+
+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
+ 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
+31 5, 2, 2, 5
+32 8, 3, 2, 7
+33 9, 3, 3, 9
+

 When a voiced frame is decoded and LTP codebook selection and indices are received, LTP coefficients are decoded using the selected codebook by choosing the vector that corresponds to the given codebook index in that codebook. This is done for each of the four subframes.
 The LPC coefficients are decoded from the LSF codebook by first adding the chosen vectors, one vector from each stage of the codebook. The resulting LSF vector is stabilized using the same method that was used in the encoder, see
 . The LSF coefficients are then converted to LPC coefficients, and passed on to the LPC synthesis filter.


+
+The final pitch lag for each subframe is assembled in silk_decode_pitch()
+ (silk_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
+
+
+
+ where lag_min and lag_max are the values from the "Minimum Lag" and
+ "Maximum Lag" columns of ,
+ respectively.
+


 The pulses signal is multiplied with the quantization gain to create the excitation signal.


+


 For voiced speech, the excitation signal e(n) is input to an LTP synthesis filter that will recreate the long term correlation that was removed in the LTP analysis filter and generate an LPC excitation signal e_LPC(n), according to





 using the pitch lag L, and the decoded LTP coefficients b_i.
+
 For unvoiced speech, the output signal is simply a copy of the excitation signal, i.e., e_LPC(n) = e(n).


+


 In a similar manner, the shortterm correlation that was removed in the LPC analysis filter is recreated in the LPC synthesis filter. The LPC excitation signal e_LPC(n) is filtered using the LTP coefficients a_i, according to





 where d_LPC is the LPC synthesis filter order, and y(n) is the decoded output signal.




+
+
+LBRR frames, if present, immediately follow the header bits, prior to any
+ regular SILK frames.
+Each frame whose LBRR flag was set includes a separate set of data for each
+ channel.
+
+
+
+

+
Symbol(s)
PDF
Condition
silence logp=15
postfilter logp=1
+silence {32767, 1}/32768
+postfilter {1, 1}/2
octave uniform (6) postfilter
period raw bits (4+octave) postfilter
gain raw bits (3) postfilter
tapset [2, 1, 1]/4 postfilter
transient logp=3
+tapset {2, 1, 1}/4 postfilter
+transient {7, 1}/8
+intra {7, 1}/8
coarse energy
tf_change
tf_select logp=1
spread [7, 2, 21, 2]/32
+tf_select {1, 1}/2
+spread {7, 2, 21, 2}/32
dyn. alloc.
alloc. trim [2, 2, 5, 10, 22, 46, 22, 10, 5, 2, 2]/128
skip (*) logp=1
intensity (*) uniform
dual (*) logp=1
+alloc. trim {2, 2, 5, 10, 22, 46, 22, 10, 5, 2, 2}/128
+skip {1, 1}/2
+intensity uniform
+dual {1, 1}/2
fine energy
residual
anticollapse logp=1 stereo && transient
+anticollapse {1, 1}/2
finalize
Order of the symbols in the CELT section of the bitstream
+Order of the symbols in the CELT section of the bitstream.
The decoder extracts information from the rangecoded bitstream in the order
described in the figure above. In some circumstances, it is
+described in the figure above. 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,
+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.
@@ 542,105 +2903,301 @@ to the application that a problem has occurred.
The transient flag encoded in the bitstream has a
probability of 1/8. When it is set, then the MDCT coefficients represent multiple
+probability of 1/8. 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. In addition to the global transient flag is a perband
binary flag to change the timefrequency (tf) resolution independently in each band. The
+binary flag to change the timefrequency (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
+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 perband
tf_change flags.
+tf_change flags.
+
The energy of each band is extracted from the bitstream in two steps according
to the same coarsefine strategy used in the encoder. First, the coarse energy is
decoded in unquant_coarse_energy() (quant_bands.c)
based on the probability of the Laplace model used by the encoder.

+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 shape of a band,
+it is perceptually important to preserve the energy in each band. CELT uses a
+threestep coarsefinefine strategy for encoding the energy in the base2 log
+domain, as implemented in quant_bands.c
+
After the coarse energy is decoded, the same allocation function as used in the
encoder is called. This determines the number of
bits to decode for the fine energy quantization. The decoding of the fine energy bits
is performed by unquant_fine_energy() (quant_bands.c).
Finally, like the encoder, the remaining bits in the stream (that would otherwise go unused)
are decoded using unquant_energy_finalise() (quant_bands.c).
+Coarse quantization of the energy uses a fixed resolution of 6 dB
+(integer part of base2 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 2D ztransform of
+the prediction filter is: A(z_l, z_b)=(1a*z_l^1)*(1z_b^1)/(1b*z_b^1)
+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 a=0 b=4915/32768
+when using intra energy.
+The timedomain 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 to not suffer desynchronization.
+We approximate the ideal
+probability distribution of the prediction error using a Laplace distribution
+with seperate parameters for each frame size in intra and interframe modes. The
+coarse energy quantization is performed by unquant_coarse_energy() and
+unquant_coarse_energy_impl() (quant_bands.c). The encoding of the Laplacedistributed values is
+implemented in ec_laplace_decode() (laplace.c).


Bit allocation is performed based only on information available to both
the encoder and decoder. The same calculations are performed in a bitexact
manner in both the encoder and decoder to ensure that the result is always
exactly the same. Any mismatch causes corruption of the decoded output.
The allocation is computed by compute_allocation() (rate.c),
which is used in both the encoder and the decoder.
+
For a given band, the bit allocation is nearly constant across
frames that use the same number of bits for Q1, yielding a
predefined signaltomask ratio (SMR) for each band. Because the
bands each have a width of one Bark, this is equivalent to modeling the
masking occurring within each critical band, while ignoring interband
masking and tonevsnoise characteristics. While this is not an
optimal bit allocation, it provides good results without requiring the
transmission of any allocation information. Additionally, the encoder
is able to signal alterations to the implicit allocation via
two means: There is an entropy coded tilt parameter can be used to tilt the
allocation to favor low or high frequencies, and there is a boost parameter
which can be used to shift large amounts of additional precision into
individual bands.
+
+
+The number of bits assigned to fine energy quantization in each band is determined
+by the bit allocation computation described in .
+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_i1]. 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).


For every encoded or decoded frame, a target allocation must be computed
using the projected allocation. In the reference implementation this is
performed by compute_allocation() (rate.c).
The target computation begins by calculating the available space as the
number of eighthbits which can be fit in the frame after Q1 is stored according
to the range coder (ec_tell_frac()) and reserving one eighthbit.
Then the two projected prototype allocations whose sums multiplied by 8 are nearest
to that value are determined. These two projected prototype allocations are then interpolated
by finding the highest integer interpolation coefficient in the range 063
such that the sum of the higher prototype times the coefficient divided by
64 plus the sum of the lower prototype multiplied is less than or equal to the
available eighthbits. During the interpolation a maximum allocation
in each band is imposed along with a threshold hard minimum allocation for
each band.
Starting from the last coded band a binary decision is coded for each
band over the minimum threshold to determine if that band should instead
recieve only the minimum allocation. This process stops at the first
nonminimum band, the first band to recieve an explicitly coded boost,
or the first band in the frame, whichever comes first.
The reference implementation performs this step in interp_bits2pulses()
using a binary search for the interpolation. (rate.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 bit is left after this, they are left unused.
+This is implemented in unquant_energy_finalise() (quant_bands.c).
+
+
+
+
+
+Many codecs transmit significant amounts of side information for
+the purpose of controlling bit allocation within a frame. Often this
+side information controls bit usage indirectly and must be carefully
+selected to achieve the desired rate constraints.
+
+The bandenergy normalized structure of Opus MDCT mode ensures that a
+constant bit allocation for the shape content of a band will result in a
+roughly constant tone to noise ratio, which provides for fairly consistent
+perceptual performance. The effectiveness of this approach is the result of
+two factors: The band energy, which is understood to be perceptually
+important on its own, is always preserved regardless of the shape precision and because
+the constant tonetonoise ratio implies a constant intraband noise to masking ratio.
+Intraband masking is the strongest of the perceptual masking effects. This structure
+means that the ideal allocation is more consistent from frame to frame than
+it is for other codecs without an equivalent structure.
+
+Because the bit allocation is used to drive the decoding of the rangecoder
+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 which produces identical results.
+
+Because all of the information required to decode a frame must be derived
+from that frame alone in order to retain robustness to packet loss the
+overhead of explicitly signaling the allocation would be considerable,
+especially for lowlatency (small frame size) applications,
+even though the allocation is relatively static.
+
+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 hardcoded table.
+
+While the bandenergy structure effectively models intraband masking,
+it ignores the weaker interband masking, bandtemporal 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 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:
+
Because the computed target will sometimes be somewhat smaller than the
available space, the excess space is divided by the number of bands, and this amount
is added equally to each band which was not forced to the minimum value.
+
+Band boost
+Allocation trim
+band skipping
+

The allocation target is separated into a portion used for fine energy
and a portion used for the Spherical Vector Quantizer (PVQ). The fine energy
quantizer operates in wholebit steps and is allocated based on an offset
fraction of the total usable space. Excess bits above the maximums are
left unallocated and placed into the rolling balance maintained during
the quantization process.
+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 lowprecision high frequency bands
+will be allocated no shape bits at all.
+
+In stereo mode there are also two additional parameters
+potentially coded as part of the allocation procedure: a parameter to allow the
+selective elimination of allocation for the 'side' in jointly coded bands,
+and a flag to deactivate joint coding. 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 which increase the effectiveness of these
+parameters. As with other signaled parameters, 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 process of allocation consists of the following steps: determining the perband
+maximum allocation vector, decoding the boosts, decoding the tilt, determining
+the remaining capacity 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
+fineenergy vs shape split, and final reallocation. This process results
+in an shape allocation perband (in 1/8th bit units), a perband fineenergy
+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.
+
+The maximum allocation vector is an approximation of the maximum space
+which 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 which can not be put to any use. The maximums
+specified by the codec reflect the average maximum. In the reference
+the maximums are provided partially computed form, in order to fit in less
+memory, as a static table (XXX cache.caps). 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 assign N
+to the number of MDCT bins covered by the band (for one channel), set LM
+to the shift value for the frame size (e.g. 0 for 120, 1 for 240, 3 for 480)
+then set i to nbBands*(2*LM+stereo). Then set the maximum for the band to
+the ith 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 truncating 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 which
+are 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, 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). Since the 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(11/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 8thbits, '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): Set 'width'
+to the number of MDCT bins in this band for all channels. Take the larger of width
+and 64, then the minimum of that value and the width times eight and set 'quanta'
+to the result. This represents a boost step size of six bits subject to limits
+of 1/bit/sample and 1/8th 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 a with dynalloc_loop_logp as the cost
+of a one, 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 while loop finishes
+boost contains the boost for this band. If boost is nonzero and dynalloc_logp
+is greater than 2 decrease dynalloc_logp. Once this process has been
+execute on all bands the band boosts have been decoded. This procedure
+is implemented around line 2352 of celt.c.
+
+At very low rates it's 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 at around 1269 of celt.c
+
+The allocation trim is a integer value from 010. 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 iff 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) then
+decode the trim value using the inverse CDF {127, 126, 124, 119, 109, 87, 41, 19, 9, 4, 2, 0}.
+
+Stereo parameters
+
+Anticollapse reservation
+
+The allocation computation first begins by setting up some initial conditions.
+'total' is set to the available remaining 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 assure that the resulting allocation will be conservative. 'anti_collapse_rsv'
+is set to 8 (8th bits) iff 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). 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 excessively an sparse spectrum and these bands
+are better served by having no allocation at all. For each coded band set thresh[band] to
+twentyfour 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 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 perband adjustments,
+'trim_offsets[]'. For each coded band take the alloc_trim and subtract 5 and LM then multiply
+the result by number of channels, the number MDCT bins in the shortest frame size for this mode,
+the number remaining bands, 2^LM, and 8. Then 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.
+
+

+
In order to correctly decode the PVQ codewords, the decoder must perform exactly the same
bits to pulses conversion as the encoder.
+In each band, the normalized shape is encoded
+using a vector quantization scheme called a "Pyramid vector quantizer".
+
+
+In
+the simplest case, the number of bits allocated in
+ is converted to a number of pulses as described
+by . Knowing the number of pulses and the
+number of samples in the band, the decoder calculates the size of the codebook
+as detailed in . 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
+ . This vector is then scaled to unit norm.
@@ 662,32 +3219,74 @@ and the whole balance are applied, respectively.
+
+
+The codeword is decoded as a uniformlydistributed integer value
+by decode_pulses() (cwrs.c).
+The codeword is converted from a unique index in the same way as specified in
+ . The indexing is based on the calculation of V(N,K)
+(denoted N(L,K) in ), which is the number of possible
+combinations of K pulses
+in N samples. The number of combinations can be computed recursively as
+V(N,K) = V(N1,K) + V(N,K1) + V(N1,K1), 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 initialise an arbitrary line, and direct
+polynomial solutions for small N. All of these methods are
+equivalent, and have different tradeoffs 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 decoding of the codeword from the index is performed as specified in
+The decoding of the codeword from the index is performed as specified in
, as implemented in function
decode_pulses() (cwrs.c).

+
+
+
The spherical codebook is decoded by alg_unquant() (vq.c).
The index of the PVQ entry is obtained from the range coder and converted to
a pulse vector by decode_pulses() (cwrs.c).
+To avoid the need for multiprecision 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 subvectors of size N/2.
+A quantized gain parameter with precision
+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 frame size
+dependent limit. The same recursive mechanism is applied for the joint coding
+of stereo audio.
The decoded normalized vector for each band is equal to
X' = y/y,
+
+
This operation is implemented in mix_pitch_and_residual() (vq.c),
which is the same function as used in the encoder.
+
+
+When the frame has the transient bit set, an anticollapse bit is decoded.
+When anticollapse is set, then the energy in each small MDCT is prevented
+from collapsing to zero. For each band of each MDCT where a collapse is
+detected, a pseudorandom signal is inserted with an energy corresponding
+to the min energy over the two previous frames. A renormalization step is
+then required to ensure that the anticollapse step did not alter the
+energy preservation property.
+
+
+
Just like each band was normalized in the encoder, the last step of the decoder before
@@ 699,12 +3298,12 @@ multiplied by the square root of the decoded energy. This is done by denormalise
The inverse MDCT implementation has no special characteristics. The
input is N frequencydomain samples and the output is 2*N timedomain
samples, while scaling by 1/2. The output is windowed using the same window
+input is N frequencydomain samples and the output is 2*N timedomain
+samples, while scaling by 1/2. The output is windowed using the same window
as the encoder. The IMDCT and windowing are performed by mdct_backward
(mdct.c). If a timedomain preemphasis
+(mdct.c). If a timedomain preemphasis
window was applied in the encoder, the (inverse) timedomain deemphasis window
is applied on the IMDCT result.
+is applied on the IMDCT result.
@@ 717,9 +3316,9 @@ If the postfilter 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_pitch1 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 postfilter taps is decoded last using
a pdf equal to [2, 1, 1]/4. Tapset zero corresponds to the filter coefficients
+inclusively. Next, the gain is decoded as three raw bits and is equal to
+G=3*(int_gain+1)/32. The set of postfilter 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,
@@ 731,22 +3330,22 @@ The postfilter response is thus computed as:
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
+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.
After the postfilter,
the signal is deemphasized using the inverse of the preemphasis filter
+After the postfilter,
+the signal is deemphasized using the inverse of the preemphasis filter
used in the encoder: 1/A(z)=1/(1alpha_p*z^1), where alpha_p=0.8500061035.
@@ 755,20 +3354,80 @@ used in the encoder: 1/A(z)=1/(1alpha_p*z^1), where alpha_p=0.8500061035.
Packet loss concealment (PLC) is an optional decoderside feature which
SHOULD be included when transmitting over an unreliable channel. Because
PLC is not part of the bitstream, there are several possible ways to
+Packet loss concealment (PLC) is an optional decoderside feature which
+SHOULD be included when transmitting over an unreliable channel. Because
+PLC is not part of the bitstream, there are several possible ways to
implement PLC with different complexity/quality tradeoffs. The PLC in
the reference implementation 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 timedomain aliasing
cancellation with the previous frame and the next frame. This is implemented
+cancellation with the previous frame and the next frame. This is implemented
in celt_decode_lost() (mdct.c).
+
+
+Switching between the Opus coding modes requires careful consideration. More
+specifically, the transitions that cannot be easily handled are the ones where
+the lower frequencies have to switch between the SILK LPbased model and the CELT
+transform model. If nothing is done, a glitch will occur for these transitions.
+On the other hand, switching between the SILKonly modes and the hybrid mode
+does not require any special treatment.
+
+
+
+There are two ways to avoid or reduce glitches during the problematic mode
+transitions: with, or without side information. Only transitions with side
+information are normatively specified. For transitions with no side
+information, it is RECOMMENDED for the decoder to use a concealment technique
+(e.g. make use of the PLC algorithm) to "fill in"
+the gap or the discontinuity caused by the mode transition. Note that this
+concealment MUST NOT be applied when switching between the SILK mode and the
+hybrid mode or vice versa. Similarly, it MUST NOT be applied when merely
+changing the bandwidth within the same mode.
+
+
+
+
+Switching with side information involves transmitting inband a 5ms
+"redundant" CELT frame within the Opus frame.
+This frame is designed to fillin the gap or discontinuity without requiring
+the decoder to conceal it. For transitons from a CELTonly frame to a
+SILKonly or hybrid frame, the redundant frame is inserted in the frame
+following the transition (i.e. the SILKonly/hybrid frame). For transitions
+from a SILKonly/hybrid frame to a CELTonly frame, the redundant frame is
+inserted in the first frame. For all SILKonly and hybrid frames (not only
+those involved in a mode transition), a binary symbol of probability 2^12
+needs to be decoded just after the SILK part of the bitstream. When the
+symbol value is 1, then the frame includes an embedded redundant frame. The
+redundant frame always starts and ends on byte boundaries. For SILKonly
+frames, the number of bytes is simply the number of whole remaining bytes.
+For hybrid frames, the number of bytes is equal to 2, plus a decoded unsigned
+integer (ec_dec_uint()) between 0 and 255. For hybrid frames, the redundant
+frame is placed at the end of the frame, after the CELT layer of the
+hybrid frame. The redundant frame is decoded like any other CELTonly frame,
+with the exception that it does not contain a TOC byte. The bandwidth
+is instead set to the same bandwidth of the current frame (for mediumband
+frames, the redundant frame is set to wideband).
+
+
+
+For CELTonly to SILKonly/hybrid transitions, the first
+2.5 ms of the redundant frame is used asis for the reconstructed
+output. The remaining 2.5 ms is overlapped and added (crossfaded using
+the square of the MDCT powercomplemantary window) to the decoded SILK/hybrid
+signal, ensuring a smooth transition. For SILKonly/hyrid to CELTonly
+transitions, only the second half of the 5ms decoded redundant frame is used.
+In that case, only a 2.5ms crossfade is applied, still using the
+powercomplemantary window.
+
+
+
+
+
@@ 800,20 +3459,11 @@ audio  ++ ++  ++
Opus uses an entropy coder based upon ,
which is itself a rediscovery of the FIFO arithmetic code introduced by .
It is very similar to arithmetic encoding, except that encoding is done with
digits in any base instead of with bits,
so it is faster when using larger bases (i.e.: an octet). All of the
calculations in the range coder must use bitexact integer arithmetic.



The range coder also acts as the bitpacker for Opus. It is
used in three different ways, to encode:
entropycoded symbols with a fixed probability model using ec_encode(), (rangeenc.c)
integers from 0 to 2^M1 using ec_enc_uint() or ec_enc_bits(), (entenc.c)
+entropycoded symbols with a fixed probability model using ec_encode(), (entenc.c)
+integers from 0 to 2**M1 using ec_enc_uint() or ec_enc_bits(), (entenc.c)
integers from 0 to N1 (where N is not a power of two) using ec_enc_uint(). (entenc.c)
@@ 826,20 +3476,15 @@ and a count of additional carrypropagating output octets. Both rng
and low are 32bit unsigned integer values, rem is an octet value or
the special value 1, and ext is an integer with at least 16 bits.
This state vector is initialized at the start of each each frame to
the value (0,2^31,1,0).



Each symbol 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. Opus only uses static
contexts; they are not adapted to the statistics of the data that is
coded.
+the value (0,2**31,1,0). The reference implementation reuses the
+'val' field of the entropy coder structure to hold low, in order to
+allow the same structure to be used for encoding and decoding, but
+we maintain the distinction here for clarity.
 The main encoding function is ec_encode() (rangeenc.c),
+ The main encoding function is ec_encode() (entenc.c),
which takes as an argument a threetuple (fl,fh,ft)
describing the range of the symbol to be encoded in the current
context, with 0 <= fl < fh <= ft <= 65535. The values of this tuple
@@ 852,17 +3497,17 @@ fl=sum(f(i),i
ec_encode() updates the state of the encoder as follows. If fl is
 greater than zero, then low = low + rng  (rng/ft)*(ftfl) and
+ greater than zero, then low = low + rng  (rng/ft)*(ftfl) and
rng = (rng/ft)*(fhfl). Otherwise, low is unchanged and
rng = rng  (rng/ft)*(fhfl). The divisions here are exact integer
division. After this update, the range is normalized.
To normalize the range, the following process is repeated until
 rng > 2^23. First, the top 9 bits of low, (low>>23), are placed into
+ rng > 2**23. First, the top 9 bits of low, (low>>23), are placed into
a carry buffer. Then, low is set to . This process is carried out by
 ec_enc_normalize() (rangeenc.c).
+ ec_enc_normalize() (entenc.c).
The 9 bits produced in each iteration of the normalization loop
@@ 874,9 +3519,9 @@ fl=sum(f(i),i
 The function ec_enc_carry_out() (rangeenc.c) performs
 this buffering. It takes a 9bit input value, c, from the normalization
 8bit output and a carry bit. If c is 0xFF, then ext is incremented
+ The function ec_enc_carry_out() (entenc.c) performs
+ this buffering. It takes a 9bit input value, c, from the normalization:
+ 8 bits of output and a carry bit. If c is 0xFF, then ext is incremented
and no octets are output. Otherwise, if rem is not the special value
1, then the octet (rem+(c>>8)) is output. Then ext octets are output
with the value 0 if the carry bit is set, or 0xFF if it is not, and
@@ 884,29 +3529,36 @@ fl=sum(f(i),i
In the reference implementation, a special version of ec_encode()
 called ec_encode_bin() (rangeenc.c) is defined to
 take a twotuple (fl,ftb), where , but avoids using division.

+
 Functions ec_enc_uint() or ec_enc_bits() are based on ec_encode() and
 encode one of N equiprobable symbols, each with a frequency of 1,
 where N may be as large as 2^321. Because ec_encode() is limited to
 a total frequency of 2^161, this is done by encoding a series of
 symbols in smaller contexts.
+ The CELT layer also allows directly encoding a series of raw bits, outside
+ of the range coder, implemented in ec_enc_bits() (entenc.c).
+ The raw bits are packed at the end of the packet, starting by storing the
+ least significant bit of the value to be packed in the least significant bit
+ of the last byte, filling up to the most significant bit in
+ the last byte, and the continuing in the least significant bit of the
+ penultimate byte, and so on.
+ This packing may continue into the last byte output by the range coder,
+ though the format should render it impossible to overwrite any set bit
+ produced by the range coder when the procedure in
+ is followed to finalize the stream.
+
+
+
 ec_enc_bits() (entenc.c) is defined, like
 ec_encode_bin(), to take a twotuple (fl,ftb), with >ftb8&0xFF) using ec_encode_bin() and
 subtracts 8 from ftb. Then, it encodes the remaining bits of fl, e.g.,
 (fl&(1<, again using ec_encode_bin().
+ The function ec_enc_uint() is based on ec_encode() and encodes one of N
+ equiprobable symbols, each with a frequency of 1, where N may be as large as
+ 2**321. Because ec_encode() is limited to a total frequency of 2**161, this
+ is done by encoding a series of symbols in smaller contexts.
ec_enc_uint() (entenc.c) takes a twotuple (fl,ft),
@@ 915,9 +3567,8 @@ fl=sum(f(i),i8, then the top 8 bits of fl
are encoded using ec_encode() with the threetuple
(fl>>ftb8,(fl>>ftb8)+1,(ft1>>ftb8)+1), and the remaining bits
 are encoded with ec_enc_bits using the twotuple
 .
+ are encoded as raw bits. Otherwise, fl is encoded with ec_encode() directly
+ using the threetuple (fl,fl+1,ft).
@@ 926,15 +3577,17 @@ fl=sum(f(i),i>23), are sent to the carry buffer, and end is replaced by
(end<<8&0x7FFFFFFF). Finally, if the value in carry buffer, 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.
After the carry buffer is finished outputting octets, the rest of the
 output buffer is padded with zero octets. Finally, rem is set to the
+ output buffer (if any) is padded with zero bits, until it reaches the raw
+ bits. Finally, rem is set to the
special value 1. This process is implemented by ec_enc_done()
 (rangeenc.c).
+ (entenc.c).
@@ 943,12 +3596,14 @@ fl=sum(f(i),i
@@ 1000,9 +3655,9 @@ fl=sum(f(i),i
 The input signal is processed by a VAD (Voice Activity Detector) to produce a measure of voice activity, and also spectral tilt and signaltonoise estimates, for each frame. The VAD uses a sequence of halfband filterbanks to split the signal in four subbands: 0  Fs/16, Fs/16  Fs/8, Fs/8  Fs/4, and Fs/4  Fs/2, where Fs is the sampling frequency, that is, 8, 12, 16 or 24 kHz. The lowest subband, from 0  Fs/16 is highpass filtered with a firstorder MA (Moving Average) filter (with transfer function H(z) = 1z^(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 an SNR (SignaltoNoise Ratio) 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:
+ The input signal is processed by a VAD (Voice Activity Detector) to produce a measure of voice activity, and also spectral tilt and signaltonoise estimates, for each frame. The VAD uses a sequence of halfband filterbanks to split the signal in four subbands: 0  Fs/16, Fs/16  Fs/8, Fs/8  Fs/4, and Fs/4  Fs/2, where Fs is the sampling frequency, that is, 8, 12, 16, or 24 kHz. The lowest subband, from 0  Fs/16 is highpass filtered with a firstorder MA (Moving Average) filter (with transfer function H(z) = 1z^(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 an SNR (SignaltoNoise Ratio) 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:
Average SNR. The average of the subband SNR values.
@@ 1048,7 +3703,7 @@ fl=sum(f(i),i
 The input signal is filtered by a highpass filter to remove the lowest part of the spectrum that contains little speech energy and may contain background noise. This is a second order ARMA (Auto Regressive Moving Average) filter with a cutoff frequency around 70 Hz.
+ The input signal is filtered by a highpass filter to remove the lowest part of the spectrum that contains little speech energy and may contain background noise. This is a second order ARMA (Auto Regressive Moving Average) filter with a cutoff frequency around 70 Hz.
In the future, a music detector may also be used to lower the cutoff frequency when the input signal is detected to be music rather than speech.
@@ 1061,8 +3716,8 @@ fl=sum(f(i),i
sampling>Correlator 
     4
 ++ ++ \/
@@ 1074,30 +3729,30 @@ fl=sum(f(i),i
 ++  ++ __________ 6
   3
  \/  \/
+  \/  \/
 ++  ++
  Whitening  Time 
+  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
+7: Pitch lags
]]>
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 Prediction 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:
+ 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 Prediction 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:
 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.
+ 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.
 The second stage operates on a 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:
+ The second stage operates on a 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
@@ 1140,9 +3795,9 @@ fl=sum(f(i),i
@@ 1177,7 +3832,7 @@ H(z) = G * ( 1  c_tilt * z^(1) ) * 
16 d
__ __
Wana(z) = (1  \ (a_ana(k) * z^(k))*(1  z^(L) \ b_ana(k)*z^(k)),
 /_ /_
+ /_ /_
k=1 k=d
]]>
@@ 1193,7 +3848,7 @@ Wana(z) = (1  \ (a_ana(k) * z^(k))*(1  z^(L) \ b_ana(k)*z^(k)),
16 d
__ __
Wsyn(z) = (1  \ (a_syn(k) * z^(k))*(1  z^(L) \ b_syn(k)*z^(k)).
 /_ /_
+ /_ /_
k=1 k=d
]]>
@@ 1281,7 +3936,7 @@ c_tilt = 0.04 + 0.06 * C
 For a frame of voiced speech the pitch pulses will remain dominant in the prewhitened input signal. Further whitening is desirable as it leads to higher quality at the same available bitrate. To achieve this, a LongTerm 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 used to find an LTP residual signal with the simulated output signal as input to obtain better modelling of the output signal. This LTP residual signal is the input to an LPC analysis where the LPCs are estimated using Burgs method, such that the residual energy is minimized. The estimated LPCs are converted to a Line Spectral Frequency (LSF) vector, and quantized as described in . After quantization, the quantized LSF vector is converted to LPC coefficients and hence by using these quantized coefficients the encoder remains fully synchronized with the decoder. The LTP coefficients are quantized using a method described in . The quantized LPC and LTP coefficients are now used to filter the highpass filtered input signal and measure a residual energy for each of the four subframes.
+ For a frame of voiced speech the pitch pulses will remain dominant in the prewhitened input signal. Further whitening is desirable as it leads to higher quality at the same available bitrate. To achieve this, a LongTerm 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 used to find an LTP residual signal with the simulated output signal as input to obtain better modelling of the output signal. This LTP residual signal is the input to an LPC analysis where the LPCs are estimated using Burgs method, such that the residual energy is minimized. The estimated LPCs are converted to a Line Spectral Frequency (LSF) vector, and quantized as described in . After quantization, the quantized LSF vector is converted to LPC coefficients and hence by using these quantized coefficients the encoder remains fully synchronized with the decoder. The LTP coefficients are quantized using a method described in . The quantized LPC and LTP coefficients are now used to filter the highpass filtered input signal and measure a residual energy for each of the four subframes.
@@ 1315,26 +3970,26 @@ LSF_q = argmin { (LSF  c)' * W * (LSF  c) + mu * rate },
We arrange the codebook in a multiple stage structure to achieve a quantizer that is both memory efficient and highly scalable in terms of computational complexity, see e.g. . In the first stage the input is the LSF vector to be quantized, and in any other stage s > 1, the input is the quantization error from the previous stage, see .
+
 c_{1,2} > c_{2,2} > ... > c_{S,2} >
++ ++ ++ res_S =
... ... ... LSFLSF_q
 ++ ++ ++
+ ++ ++ ++
c_{1,M11} c_{2,M21} c_{S,MS1}
 ++ ++ ++
+ ++ ++ ++
 c_{1,M1}   c_{2,M2}   c_{S,MS} 
++ ++ ++
]]>
MultiStage LSF Vector Codebook Structure.

By storing total of M codebook vectors, i.e.,
@@ 1360,12 +4015,12 @@ T =   Ms
]]>
 possible combinations for generating the quantized vector. It is for example possible to represent 2^36 uniquely combined vectors using only 216 vectors in memory, as done in SILK for voiced speech at all sample frequencies above 8 kHz.
+ possible combinations for generating the quantized vector. It is for example possible to represent 2**36 uniquely combined vectors using only 216 vectors in memory, as done in SILK for voiced speech at all sample frequencies above 8 kHz.
 This number of possible combinations is far too high for a full search to be carried out for each frame so for all stages but the last, i.e., s smaller than S, only the best min( L, Ms ) centroids are carried over to stage s+1. In each stage the objective function, i.e., the weighted sum of accumulated bitrate and distortion, is evaluated for each codebook vector entry and the results are sorted. Only the best paths and the corresponding quantization errors are considered in the next stage. In the last stage S the single best path through the multistage codebook is determined. By varying the maximum number of survivors from each stage to the next L, the complexity can be adjusted in realtime at the cost of a potential increase when evaluating the objective function for the resulting quantized vector. This approach scales all the way between the two extremes, L=1 being a greedy search, and the desirable but infeasible full search, L=T/MS. In fact, a performance almost as good as what can be achieved with the infeasible full search can be obtained at a substantially lower complexity by using this approach, see e.g. .
+ This number of possible combinations is far too high for a full search to be carried out for each frame so for all stages but the last, i.e., s smaller than S, only the best min( L, Ms ) centroids are carried over to stage s+1. In each stage the objective function, i.e., the weighted sum of accumulated bitrate and distortion, is evaluated for each codebook vector entry and the results are sorted. Only the best paths and the corresponding quantization errors are considered in the next stage. In the last stage S the single best path through the multistage codebook is determined. By varying the maximum number of survivors from each stage to the next L, the complexity can be adjusted in realtime at the cost of a potential increase when evaluating the objective function for the resulting quantized vector. This approach scales all the way between the two extremes, L=1 being a greedy search, and the desirable but infeasible full search, L=T/MS. In fact, a performance almost as good as what can be achieved with the infeasible full search can be obtained at a substantially lower complexity by using this approach, see e.g. .
@@ 1438,17 +4093,17 @@ Inverse of the postfilter
The MDCT implementation has no special characteristics. The
input is a windowed signal (after preemphasis) of 2*N samples and the output is N
frequencydomain samples. A lowoverlap window is used to reduce the algorithmic delay.
+frequencydomain samples. A lowoverlap window is used to reduce the algorithmic delay.
It is derived from a basic (full overlap) window that is the same as the one used in the Vorbis codec: W(n)=[sin(pi/2*sin(pi/2*(n+.5)/L))]^2. The lowoverlap window is created by zeropadding the basic window and inserting ones in the middle, such that the resulting window still satisfies power complementarity. The MDCT is computed in mdct_forward() (mdct.c), which includes the windowing operation and a scaling of 2/N.
The MDCT output is divided into bands that are designed to match the ear's critical
+The MDCT output is divided into bands that are designed to match the ear's critical
bands for the smallest (2.5ms) frame size. The larger frame sizes use integer
multiplies of the 2.5ms layout. For each band, the encoder
computes the energy that will later be encoded. Each band is then normalized by the
+computes the energy that will later be encoded. Each band is then normalized by the
square root of the nonquantized 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.
@@ 1462,7 +4117,7 @@ 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 shape of a band,
it is perceptually important to preserve the energy in each band. CELT uses a
coarsefine strategy for encoding the energy in the base2 log domain,
+coarsefine strategy for encoding the energy in the base2 log domain,
as implemented in quant_bands.c
@@ 1488,7 +4143,7 @@ clamping must be implemented in all encoders and decoders.
We approximate the ideal
probability distribution of the prediction error using a Laplace distribution
with seperate parameters for each frame size in intra and interframe modes. The
coarse energy quantization is performed by quant_coarse_energy() and
+coarse energy quantization is performed by quant_coarse_energy() and
quant_coarse_energy() (quant_bands.c). The encoding of the Laplacedistributed values is
implemented in ec_laplace_encode() (laplace.c).
@@ 1498,12 +4153,12 @@ implemented in ec_laplace_encode() (laplace.c).
After the coarse energy quantization and encoding, the bit allocation is computed
+After the coarse energy quantization and encoding, the bit allocation is computed
( ) and the number of bits to use for refining the
energy quantization is determined for each band. Let B_i be the number of fine energy bits
+energy quantization is determined for each band. 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_i1]. 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()
+energy quantization is implemented in quant_fine_energy()
(quant_bands.c).
@@ 1529,15 +4184,15 @@ energy precision. This is implemented in quant_energy_finalise()
codebook 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
+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 the PVQ is used to encode
the unit vector that results from the normalization in
 directly. Given a PVQ codevector y,
the unit vector X is obtained as X = y/y, where . denotes the
+the unit vector that results from the normalization in
+ directly. Given a PVQ codevector y,
+the unit vector X is obtained as X = y/y, where . denotes the
L2 norm.
@@ 1546,9 +4201,9 @@ L2 norm.
The search for the best codevector y is performed by alg_quant()
(vq.c). There are several possible approaches to the
+(vq.c). There are several possible approaches to the
search with a tradeoff between quality and complexity. The method used in the reference
implementation computes an initial codeword y1 by projecting the residual signal
+implementation computes an initial codeword y1 by projecting the residual signal
R = X  p' onto the codebook pyramid of K1 pulses:
@@ 1556,8 +4211,8 @@ y0 = round_towards_zero( (K1) * R / sum(abs(R)))
Depending on N, K and the input data, the initial codeword y0 may contain from
0 to K1 nonzero values. All the remaining pulses, with the exception of the last one,
+Depending on N, K and the input data, the initial codeword y0 may contain from
+0 to K1 nonzero 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 R:
@@ 1578,32 +4233,12 @@ codebook and the implementors MAY use any other search methods.
The best PVQ codeword is encoded as a uniformlydistributed integer value
by encode_pulses() (cwrs.c).
The codeword is converted to a unique index in the same way as specified in
 . The indexing is based on the calculation of V(N,K) (denoted N(L,K) in ), which is the number of possible combinations of K pulses
in N samples. 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 initialise an arbitrary line, and direct
polynomial solutions for small N. All of these methods are
equivalent, and have different tradeoffs 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 codeword is converted from a unique index in the same way as specified in
+ . The indexing is based on the calculation of V(N,K)
+(denoted N(L,K) in ), which is the number of possible
+combinations of K pulses in N samples.

The indexing computations are performed using 32bit unsigned integers. For large codebooks,
32bit integers are not sufficient. Instead of using 64bit integers (or more), the encoding
is for these cases is handled by splitting each band into two equal vectors of
size N/2 prior to quantization. A quantized gain parameter with precision
derived from the current allocation is entropy coded to represent the relative gains of each side of
the split and the entire quantization process is recursively applied.
Multiple levels of splitting may be applied upto a frame size dependent limit.
The same recursive mechanism is applied for the joint coding of stereo
audio.

@@ 1632,7 +4267,7 @@ Let m=M/M and s=S/S; m and s are separately encoded with the PVQ encoder
After all the quantization is completed, the quantized energy is used along with the
+After all the quantization is completed, the quantized energy is used along with the
quantized normalized band data to resynthesize the MDCT spectrum. The inverse MDCT ( ) and the weighted overlapadd are applied and the signal is stored in the synthesis
buffer .
The encoder MAY omit this step of the processing if it does not need the decoded output.
@@ 1641,7 +4276,7 @@ The encoder MAY omit this step of the processing if it does not need the decoded
Each CELT frame can be encoded in a different number of octets, making it possible to vary the bitrate at will. This property can be used to implement sourcecontrolled variable bitrate (VBR). Support for VBR is OPTIONAL for the encoder, but a decoder MUST be prepared to decode a stream that changes its bitrate dynamically. The method used to vary the bitrate in VBR mode is left to the implementor, as long as each frame can be decoded by the reference decoder.
+Each CELT frame can be encoded in a different number of octets, making it possible to vary the bitrate at will. This property can be used to implement sourcecontrolled variable bitrate (VBR). Support for VBR is OPTIONAL for the encoder, but a decoder MUST be prepared to decode a stream that changes its bitrate dynamically. The method used to vary the bitrate in VBR mode is left to the implementor, as long as each frame can be decoded by the reference decoder.
@@ 1653,47 +4288,66 @@ Each CELT frame can be encoded in a different number of octets, making it possib
It is the intention to allow the greatest possible choice of freedom in
+It is the intention to allow the greatest possible choice of freedom in
implementing the specification. For this reason, outside of a few exceptions
noted in this section, conformance is defined through the reference
implementation of the decoder provided in Appendix .
Although this document includes an English description of the codec, should
the description contradict the source code of the reference implementation,
+implementation of the decoder provided in .
+Although this document includes an English 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 a decoder's output MUST be
within the thresholds specified compared to the reference implementation
using the opus_compare.m tool in Appendix .
+ within the thresholds specified by the opus_compare.c tool in
+ compared to the reference implementation.
+
+
+To complement the Opus specification, the "Opus Custom" codec is defined to
+handle special sampling 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, 20 ms is
+needed (for either complexity or latency reasons). Such applications will not
+be compatible with the "main" Opus codec. In Opus Custom operation,
+only the CELT later is available, which is available using the celt_* function
+calls in celt.h.
+
+
The codec needs to take appropriate security considerations
+The codec needs to take appropriate security considerations
into account, as outlined in and .
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 much more resources to decode. Although problems
+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 stream 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 crafter packet or audio segment could cause a significant increase
in CPU load. However, on certain CPU architectures where denormalized
floatingpoint operations are much slower it is possible for some audio content
(e.g. silence or nearsilence) to cause such an increase
in CPU load. For such architectures, it is RECOMMENDED to add very small
floatingpoint offsets to prevent significant numbers of denormalized
operations or to configure the hardware to zeroize denormal numbers.
+ a specially crafted packet or audio segment could cause a significant increase
+ in CPU load.
+However, on certain CPU architectures where denormalized floatingpoint
+ operations are much slower than normal floatingpoint operations it is
+ possible for some audio content (e.g., silence or nearsilence) to cause such
+ 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 an implementation
+ avoids them.
+For such architectures, it is RECOMMENDED that one add very small
+ floatingpoint offsets to prevent significant numbers of denormalized
+ operations or to configure the hardware to treat denormals as zero (DAZ).
+
No such issue exists for the fixedpoint reference implementation.

+
@@ 1704,10 +4358,13 @@ This document has no actions for IANA.
Thanks to all other developers, including Raymond Chen, Soeren Skak Jensen, Gregory Maxwell,
Christopher Montgomery, Karsten Vandborg Soerensen, and Timothy Terriberry.
+Thanks to all other developers, including Raymond Chen, Soeren Skak Jensen, Gregory Maxwell,
+Christopher Montgomery, Karsten Vandborg Soerensen, and Timothy Terriberry. We would also
+like to thank Igor Dyakonov, Jan Skoglund for their help with subjective testing of the
+Opus codec. Thanks to John Ridges, Keith Yan and many others on the Opus and CELT mailing lists
+for their bug reports and feeback.

+
@@ 1771,7 +4428,7 @@ Christopher Montgomery, Karsten Vandborg Soerensen, and Timothy Terriberry.
 Efficient Search and Design Procedures for Robust MultiStage VQ of LPC Parameters for 4 kb/s Speech Coding
+ Efficient Search and Design Procedures for Robust MultiStage VQ of LPC Parameters for 4 kb/s Speech Coding
@@ 1847,7 +4504,7 @@ Christopher Montgomery, Karsten Vandborg Soerensen, and Timothy Terriberry.

+
@@ 1865,15 +4522,15 @@ Christopher Montgomery, Karsten Vandborg Soerensen, and Timothy Terriberry.

+

+
This appendix contains the complete source code for the
reference implementation of the Opus codec written in C. This
implementation can be compiled for
+implementation can be compiled for
either floatingpoint or fixedpoint architectures.
@@ 1903,6 +4560,15 @@ tar xzvf opus_source.tar.gz
+
+
+The current development version of the source code is available in a
+ Git repository .
+Development snapshots are provided at
+ .
+
+
+
@@ 1911,9 +4577,9 @@ tar xzvf opus_source.tar.gz
