XGitUrl: http://git.xiph.org/?p=opus.git;a=blobdiff_plain;f=doc%2Fdraftietfcodecopus.xml;h=bc7d3746ce26bc5ff5fd4f164b9f4d248ededce8;hp=693d03b1f159276ed20e144e9400d2860f5b6e17;hb=45b27da44c042e93ca154439ef5fc3b30d05ddaa;hpb=037f20a77954cf130da2d61a5bce3f22bd3e7342
diff git a/doc/draftietfcodecopus.xml b/doc/draftietfcodecopus.xml
index 693d03b1..bc7d3746 100644
 a/doc/draftietfcodecopus.xml
+++ b/doc/draftietfcodecopus.xml
@@ 2,7 +2,7 @@

+Definition of the Opus Audio Codec
@@ 53,7 +53,7 @@

+
General
@@ 131,8 +131,7 @@ The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD",
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
+The notation "Q<n>", 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.
@@ 249,6 +248,24 @@ This approach ensures a sender and receiver can always interoperate, regardless
+Opus defines superwideband (SWB) mode to have an effective sampling rate of
+ 24 kHz, unlike some other audio coding standards that use 32 kHz.
+This was chosen for a number of reasons.
+The band layout in the MDCT layer naturally allows skipping coefficients for
+ frequencies over 12 kHz, but does not allow cleanly dropping frequencies
+ over 16 kHz.
+The choice of 24 kHz also makes resampling in the MDCT layer easier, as 24
+ evenly divides 48, and when 24 kHz is sufficient, it can save computation
+ in other processing, such as Acoustic Echo Cancellation (AEC).
+Experimental changes to the band layout to allow a 16 kHz cutoff showed
+ potential quality degredations, and at typical bitrates the number of bits
+ saved by using such a cutoff instead of coding in fullband (FB) mode is very
+ small.
+Therefore, if an application wishes to process a signal sampled at 32 kHz,
+ it should just use FB mode.
+
+
+
The LP layer is based on the
SILK codec
.
@@ 293,7 +310,7 @@ 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
+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
@@ 321,18 +338,34 @@ As described, the two layers can be combined in three possible operating modes:
An MDCTonly mode for very low delay speech transmission as well as music
transmission.
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.
+
+
+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.
+This section describes the possible combinations of these parameters and the
+ internal framing used to pack multiple frames into a single packet.
+This framing is not selfdelimiting.
+Instead, it assumes that a higher layer (such as UDP or RTP or Ogg or Matroska)
+ will communicate the length, in bytes, of the packet, and it uses this
+ information to reduce the framing overhead in the packet itself.
+A decoder implementation MUST support the framing described in this section.
+An alternative, selfdelimiting variant of the framing is described in
+ .
+Support for that variant is OPTIONAL.
+
+
+
+
+An Opus packet begins with a singlebyte tableofcontents (TOC) header that
+ 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.

+
+
+
+
+This section describes how frames are packed according to each possible value
+ of "c" in the TOC byte.
+
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)
+0: No frame (discontinuous transmission (DTX) or lost packet)
 rate +
+ +>decoder> rate +
bit ++    conversion v
stream  Range + ++ ++ /\ audio
>decoder  + >
  + ++ ++ \/
 ++   CELT   Delay  ^
 +>decoder compens +
    ation 
 ++ ++
+  + ++ \/
+ ++   CELT  ^
+ +>decoder+
+  
+ ++
]]>
@@ 713,41 +777,59 @@ 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.
+Symbols may also be coded as "raw bits" packed directly into the bitstream,
+ bypassing the range coder.
+These are packed backwards starting at the end of the frame, as illustrated in
+ .
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.
+
+
+ :
++ +
+: :
++ ++++++++++++++++++++++++++++++
+:  < Boundary occurs at an arbitrary bit position :
+++++ +
+: < Raw bits data (packed LSb to MSb) 
++++++++++++++++++++++++++++++++++
+]]>
+
+
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.
+ 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.
+Suppose there is a context with n symbols, identified with an index that ranges
+ from 0 to n1.
+The parameters needed to encode or decode a symbol in this context are
+ represented by a threetuple (fl[k], fh[k], ft), with
+ 0 <= fl[k] < fh[k] <= ft <= 65535.
The values of this tuple are derived from the probability model for the
 symbol, represented by traditional frequency counts
 (although, since Opus uses static contexts, these are not updated as symbols
 are decoded).
Let f[i] be the frequency of the ith symbol in a
 context with n symbols total.
Then the threetuple corresponding to the kth
 symbol is given by
+ 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 symbol i.
+Then the threetuple corresponding to symbol k is given by
@@ 760,8 +842,10 @@ The range decoder maintains an internal state vector composed of the twotuple
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
 .
+The remaining bit is saved for use in the renormalization procedure described
+ in , which the decoder invokes
+ immediately after initialization to read additional bits and establish the
+ invariant that rng > 2**23.
@@ 769,48 +853,79 @@ 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 second step updates the range decoder state with the threetuple
+ (fl[k], fh[k], 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.
+ fs; i.e., the value of k whose threetuple (fl[k], fh[k], ft)
+ satisfies fl[k] <= fs < fh[k].
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.
+
+
+
+If fl[k] is greater than zero, then the decoder updates rng using
+
+
+
+Otherwise, it updates rng using
+
+
+
+
+
+Using a special case for the first symbol (rather than the last symbol, as is
+ commonly done in other arithmetic coders) ensures that all the truncation
+ error from the finite precision arithmetic accumulates in symbol 0.
+This makes the cost of coding a 0 slightly smaller, on average, than its
+ estimated probability indicates and makes the cost of coding any other symbol
+ slightly larger.
When contexts are designed so that 0 is the most probable symbol, which is
often the case, this strategy minimizes the inefficiency introduced by the
finite precision.
+It also makes some of the specialcase decoding routines in
+ particularly simple.
+
+
+After the updates, implemented by ec_dec_update() (entdec.c), the decoder
+ normalizes the range using the procedure in the next section, and returns the
+ index k.
To normalize the range, the decoder repeats the following process, implemented
 by ec_dec_normalize() (entdec.c), until rng > 2**23.
+ 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.
+Then it reads the next octet of the payload and combines it with the leftover
+ bit buffered from the previous octet to form the 8bit value sym.
+It takes the leftover bit as the high bit (bit 7) of sym, and the top 7 bits
+ of the octet it just read as the other 7 bits of sym.
+The remaining bit in the octet just read is buffered for use in the next
+ iteration.
If no more input octets remain, it uses zero bits instead.
Then, it sets val to (val<<8)+(255sym)&0x7FFFFFFF.
+Then, it sets
+
+
+
It is normal and expected that the range decoder will read several bytes
@@ 823,7 +938,7 @@ The encoder is expected to terminate the stream in such a way that the decoder
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
+ if there is additional data in the current packet from padding or other
frames.
@@ 867,10 +982,12 @@ The next is ec_dec_bit_logp() (entdec.c), which decodes a single binary symbol,
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
+ ft = (1<<logp), followed by ec_dec_update() with
+ the 3tuple (fl[k] = 0, fh[k] = (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
+ (fl[k] = (1<<logp)1,
+ fh[k] = ft = (1<<logp)) otherwise (a "1" was
decoded).
The implementation requires no multiplications or divisions.
@@ 881,20 +998,20 @@ 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.
+ ("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).
+idcf[k], on the other hand, stores (1<<ftb)fh[k], which is equal to
+ (1<<ftb)fl[k+1].
+fl[0] is assumed to be 0, and the table is terminated by a value of 0 (where
+ fh[k] == ft).
The function is mathematically equivalent to calling ec_decode() with
 ft = (1<<ftb), using the returned value fs to search the table for the
 first entry where fs < (1<<ftb)icdf[k], and calling
 ec_dec_update() with fl = (1<<ftb)icdf[k1] (or 0 if k == 0),
 fh = (1<<ftb)idcf[k], and ft = (1<<ftb).
+ ft = (1<<ftb), using the returned value fs to search the table
+ for the first entry where fs < (1<<ftb)icdf[k], and
+ calling ec_dec_update() with fl[k] = (1<<ftb)icdf[k1] (or 0
+ if k == 0), fh[k] = (1<<ftb)idcf[k], and
+ ft = (1<<ftb).
Combining the search with the update allows the division to be replaced by a
series of multiplications (which are usually much cheaper), and using an
inverse CDF allows the use of an ftb as large as 8 in an 8bit table without
@@ 927,10 +1044,9 @@ In such contexts, ec_dec_icdf() can decode the symbol by using a table that
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 least significant bit of the first value packed in the least significant
+ bit of the last byte, filling up to the most significant bit in the last byte,
+ continuing on to the least significant bit of the penultimate byte, and so on.
The reference implementation reads them using ec_dec_bits() (entdec.c).
Because the range decoder must read several bytes ahead in the stream, as
described in , the input consumed by the
@@ 952,7 +1068,7 @@ Because ec_decode() is limited to a total frequency of 2**161, this is split
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
+ 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
@@ 1010,22 +1126,22 @@ In practice, although the number of bits used so far is an upper bound,
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.
+For a range coder symbol that requires a whole number of bits (i.e.,
+ ft/(fh[k]fl[k]) is a power of two), where there are at least p 1/8th bits
+ available, decoding the symbol will never advance the decoder past the end of
+ the frame ("bust the budget").
+In this case the return value of ec_tell_frac() will only advance by more than
+ p 1/8th bits if there was an additional, fractional number of bits remaining,
+ and it will never advance beyond the next wholebit boundary, which is safe,
+ since frames always contain a whole number of bits.
However, when p is not a whole number of bits, an extra 1/8th bit is required
 to ensure decoding the symbol will not bust.
+ to ensure that decoding the symbol will not bust the budget.
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.
+ have been processed by the decoder so far in the variable nbits_total,
+ including the (possibly fractional) number of bits that are currently
+ buffered, but not consumed, inside the range coder.
nbits_total is initialized to 33 just after the initial range renormalization
process completes (or equivalently, it can be initialized to 9 before the
first renormalization).
@@ 1085,16 +1201,24 @@ When used in a hybrid frame in SWB or FB mode, the LP layer itself still only
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.
+ 10 ms regular SILK frame or between one and three 20 ms regular SILK
+ frames.
+A stereo Opus frame may double the number of regular SILK frames (up to a total
+ of six), since it includes separate frames for a mid channel and, optionally,
+ a side channel.
Optional Low BitRate Redundancy (LBRR) frames, which are reducedbitrate
 encodings of previous SILK frames, may appear to aid in recovery from packet
 loss.
+ encodings of previous SILK frames, may be included to aid in recovery from
+ packet loss.
If present, these appear before the regular SILK frames.
They are in most respects identical to regular active SILK frames, except that
 they are usually encoded with a lower bitrate, 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.
+They are in most respects identical to regular, active SILK frames, except that
+ they are usually encoded with a lower bitrate.
+This draft uses "SILK frame" to refer to either one and "regular SILK frame" if
+ it needs to draw a distinction between the two.
+
+
+Each SILK frame is in turn composed of either two or four 5 ms subframes.
+Various parameters, such as the quantization gain of the excitation and the
+ pitch lag and filter coefficients can vary on a subframebysubframe basis.
All of these frames and subframes are decoded from the same range coder, with
@@ 1117,15 +1241,31 @@ It would be required to do so anyway for hybrid Opus frames, or to support
Symbol(s)
PDF
+PDF(s)Condition
VAD flags{1, 1}/2
LBRR flag{1, 1}/2
Perframe LBRR flags
Frame Type
Gain index
+
+VAD flags
+{1, 1}/2
+
+
+LBRR flag
+{1, 1}/2
+
+
+Perframe LBRR flags
+
+
+
+LBRR Frame(s)
+
+
+
+Regular SILK Frame(s)
+
+
+
Order of the symbols in the SILK section of the bitstream.
+Organization of the SILK layer of an Opus frame.
@@ 1161,7 +1301,7 @@ An overview of the decoder is given in .
 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.
+ The range decoder decodes the encoded parameters from the received bitstream. Output from this function includes the pulses and gains for generating the excitation signal, 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.
@@ 1172,7 +1312,7 @@ An overview of the decoder is given in .
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 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.
@@ 1185,7 +1325,7 @@ An overview of the decoder is given in .
 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
+ For voiced speech, the excitation signal e(n) is input to an LTP synthesis filter that recreates the longterm correlation removed in the LTP analysis filter and generates an LPC excitation signal e_LPC(n), according to
60 ms {0, 41, 20, 29, 41, 15, 28, 82}/256
+
+
+
+The LBRR frames, if present, immediately follow, one per set LBRR flag, and
+ prior to any regular SILK frames.
+ describes their exact contents.
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
+LBRR frames are only meant to be transmitted for active speech, thus all LBRR
frames are treated as active.
+
+
+In a stereo Opus frame longer than 20 ms, although all the perframe LBRR
+ flags for the mid channel are coded before the perframe LBRR flags for the
+ side channel, the LBRR frames themselves are interleaved.
+The LBRR frame for the mid channel of a given 20 ms interval (if present)
+ is immediately followed by the corresponding LBRR frame for the side channel
+ (if present).
+
+
+
+
+
+The regular SILK frame(s) follow the LBRR frames (if any).
+ describes their contents, as well.
+Unlike the LBRR frames, a regular SILK frame is always coded for each time
+ interval in an Opus frame, even if the corresponding VAD flag is unset.
+Like the LBRR frames, in stereo Opus frames longer than 20 ms, the mid and
+ side frames are interleaved for each 20 ms interval.
+The side frame may be skipped by coding an appropriate flag, as detailed in
+ .
+

+
Each SILK frame includes a set of side information that encodes the frame type,
 quantization type and gains, shortterm prediction filter coefficients, LSF
+ quantization type and gains, shortterm prediction filter coefficients, an LSF
interpolation weight, longterm prediction filter lags and gains, and a
 pseudorandom number generator (PRNG) seed.
This is followed by the quantized excitation signal.
+ linear congruential generator (LCG) seed.
+The quantized excitation signal follows these at the end of the frame.
+ details the overall organization of a
+ SILK frame.
+
+
+
+Symbol(s)
+PDF(s)
+Condition
+
+Stereo Prediction Weights
+
+
+
+MidOnly Flag
+
+
+
+Frame Type
+
+
+
+Subframe Gains
+
+
+
+Normalized LSF Stage 1 Index
+
+
+
+Normalized LSF Stage 2 Residual
+
+
+
+Normalized LSF Interpolation Weight
+
+
+
+Primary Pitch Lag
+
+Voiced frame
+
+Subframe Pitch Contour
+
+Voiced frame
+
+Periodicity Index
+
+Voiced frame
+
+LTP Filter
+
+Voiced frame
+
+LTP Scaling
+
+
+
+LCG Seed
+
+
+
+Excitation Rate Level
+
+
+
+Excitation Pulse Counts
+
+
+
+Excitation Pulse Locations
+
+Nonzero pulse count
+
+Excitation LSb's
+
+
+
+Excitation Signs
+
+
+
+
+Order of the symbols in an individual SILK frame.
+
+
+
+
+
+A SILK frame corresponding to the mid channel of a stereo Opus frame begins
+ with a pair of side channel prediction weights, designed such that zeros
+ indicate normal midside coupling.
+Since these weights can change on every frame, the first portion of each frame
+ linearly interpolates between the previous weights and the current ones, using
+ zeros for the previous weights if none are available.
+These prediction weights are never included in a mono Opus frame, and the
+ previous weights are reset to zeros on any transition from a mono to stereo.
+They are also not included in an LBRR frame for the side channel, even if the
+ LBRR flags indicate the corresponding mid channel was not coded.
+In that case, the previous weights are used, again substituting in zeros if no
+ previous weights are available since the last decoder reset.
+
+
+
+The prediction weights are coded in three separate pieces, which are decoded
+ by silk_stereo_decode_pred() (silk_decode_stereo_pred.c).
+The first piece jointly codes the highorder part of a table index for both
+ weights.
+The second piece codes the loworder part of each table index.
+The third piece codes an offset used to linearly interpolate between table
+ indices.
+The details are as follows.
+
+
+
+Let n be an index decoded with the 25element stage1 PDF in
+ .
+Then let i0 and i1 be indices decoded with the stage2 and stage3 PDFs in
+ , respectively, and let i2 and i3
+ be two more indices decoded with the stage2 and stage3 PDFs, all in that
+ order.
+
+
+
+Stage
+PDF
+Stage 1
+{7, 2, 1, 1, 1,
+ 10, 24, 8, 1, 1,
+ 3, 23, 92, 23, 3,
+ 1, 1, 8, 24, 10,
+ 1, 1, 1, 2, 7}/256
+
+Stage 2
+{85, 86, 85}/256
+
+Stage 3
+{51, 51, 52, 51, 51}/256
+
+
+
+Then use n, i0, and i2 to form two table indices, wi0 and wi1, according to
+
+
+
+ where the division is exact integer division.
+The range of these indices is 0 to 14, inclusive.
+Let w[i] be the i'th weight from .
+Then the two prediction weights, w0_Q13 and w1_Q13, are
+
+> 16)*(2*i3 + 1)
+
+w0_Q13 = w_Q13[wi0]
+ + ((w_Q13[wi0+1]  w_Q13[wi0])*6554) >> 16)*(2*i1 + 1)
+  w1_Q13
+]]>
+
+
+
+Index
+Weight (Q13)
+ 013732
+ 110050
+ 28266
+ 37526
+ 46500
+ 55000
+ 62950
+ 7820
+ 8820
+ 92950
+105000
+116500
+127526
+138266
+1410050
+1513732
+
+
+
+
+
+
+A flag appears after the stereo prediction weights that indicates if only the
+ mid channel is coded for this time interval.
+It is omitted when there are no stereo weights, i.e., unless the SILK frame
+ corresponds to the mid channel of a stereo Opus frame, and it is also omitted
+ for an LBRR frame when the corresponding LBRR flags indicate the side channel
+ is present.
+When present, the decoder reads a single value using the PDF in
+ , as implemented in
+ silk_stereo_decode_mid_only() (silk_decode_stereo_pred.c).
+If the flag is set, then there is no corresponding SILK frame for the side
+ channel, the entire decoding process for the side channel is skipped, and
+ zeros are used during the stereo unmixing process.
+As stated above, LBRR frames still include this flag when the LBRR flag
+ indicates that the side channel is not coded.
+In that case, if this flag is zero (indicating that there should be a side
+ channel), then Packet Loss Concealment (PLC, see
+ ) SHOULD be invoked to recover a
+ side channel signal.
+
+
+
+PDF
+{192, 64}/256
+
+
+
+
Each SILK frame begins with a single frame type
 symbol that jointly codes the signal type and quantization offset type of the
 corresponding frame.
+Each SILK frame contains a single "frame type" symbol that jointly codes the
+ signal type and quantization offset type of the corresponding frame.
If the current frame is a regular SILK frame whose VAD bit was not set (an
 inactive frame), then the frame type symbol takes
 on the value either 0 or 1 and is decoded using the first PDF in
 .
+ "inactive" frame), then the frame type symbol takes on a value of 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
+ (an "active" frame), then the value of the symbol may range 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
@@ 1305,17 +1686,17 @@ If the frame is an LBRR frame or a regular SILK frame whose VAD flag was set
Frame TypeSignal TypeQuantization Offset Type
0Inactive0
1Inactive1
2Unvoiced0
3Unvoiced1
4Voiced0
5Voiced1
+0InactiveLow
+1InactiveHigh
+2UnvoicedLow
+3UnvoicedHigh
+4VoicedLow
+5VoicedHigh

+
A separate quantization gain is coded for each 5 ms subframe.
These gains control the step size between quantization levels of the excitation
@@ 1326,9 +1707,14 @@ The quantization gains are themselves uniformly quantized to 6 bits on a
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.
+For the first LBRR frame, an LBRR frame where the previous LBRR frame in the
+ same channel is not coded, or the first regular SILK frame in the current
+ channel of an Opus frame, the first subframe uses an independent coding
+ method.
+In a stereo Opus frame, the midonly flag (from
+ ) may cause the first regular SILK frame in
+ the side channel to occur in a later time interval than the first regular SILK
+ frame in the mid channel.
The 3 most significant bits of the quantization gain are decoded using a PDF
selected from based on the
decoded signal type.
@@ 1339,8 +1725,8 @@ The 3 most significant bits of the quantization gain are decoded using a PDF
Signal TypePDFInactive{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
+Unvoiced{2, 17, 45, 60, 62, 47, 19, 4}/256
+Voiced{1, 3, 26, 71, 94, 50, 9, 2}/256
@@ 1355,7 +1741,12 @@ The 3 least significant bits are decoded using a uniform PDF:
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 gain from the previous subframe (in the same channel).
+In particular, unlike an LBRR frame where the previous frame is not coded, in a
+ 60 ms stereo Opus frame, if the first and third regular SILK frames
+ in the side channel are coded, but the second is not, the first subframe of
+ the third frame is still coded relative to the last subframe in the first
+ frame.
The PDF in yields a delta gain index
between 0 and 40, inclusive.
@@ 1380,14 +1771,13 @@ log_gain = min(max(2*gain_index  16,
silk_gains_dequant() (silk_gain_quant.c) dequantizes the gain for the
 kth subframe and converts it into a linear Q16
 scale factor via

+ 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.
@@ 1409,13 +1799,14 @@ Otherwise, silk_log2lin uses


+
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.
+Normalized Line Spectral Frequency (LSF) coefficients follow the quantization
+ gains in the bitstream, and represent the Linear Predictive Coding (LPC)
+ coefficients for the current SILK frame.
+Once decoded, the normalized LSFs 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
@@ 1425,14 +1816,27 @@ Because of nonlinear effects in the decoding process, an implementation SHOULD
An encoder SHOULD also use the same process.
The normalized LSFs are coded using a twostage vector quantizer (VQ).
+The normalized LSFs are coded using a twostage vector quantizer (VQ)
+ ( and ).
NB and MB frames use an order10 predictor, while WB frames use an order16
predictor, and thus have different sets of tables.
+After reconstructing the normalized LSFs
+ (), the decoder runs them through a
+ stabilization process (), interpolates
+ them between frames (), converts them
+ back into LPC coefficients (), and then runs
+ them through further processes to limit the range of the coefficients
+ () and the gain of the filter
+ ().
+All of this is necessary to ensure the reconstruction process is stable.
+
+
+
+
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 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.
@@ 1477,6 +1881,9 @@ The actual codebook elements are listed in
+
+
+
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
@@ 1666,7 +2073,7 @@ 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.
+ to give an index in the range 4 to 4, inclusive.
If the index is either 4 or 4, it reads a second symbol using the PDF in
, and adds the value of this second symbol
to the index, using the same sign.
@@ 1726,14 +2133,13 @@ Each coefficient selects its prediction weight from one of the two lists based
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 kth
 coefficient selected by this process for
 0 <= k < d_LPC1.
+ 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) ,
+res_Q10[k] = (k+1 < d_LPC ? (res_Q10[k+1]*pred_Q8[k])>>8 : 0)
+ + ((((I2[k]<<10) + sign(I2[k])*102)*qstep)>>16) ,
]]>
where qstep is the Q16 quantization step size, which is 11796 for NB and MB
@@ 1885,13 +2291,22 @@ Then, the stage2 residual for each coefficient is computed via
C C D C C D D D C C D C C D C
+
+
+
+
+Once the stage1 index I1 and the stage2 residual res_Q10[] have been decoded,
+ the final normalized LSF coefficients can be reconstructed.
+
The spectral distortion introduced by the quantization of each LSF coefficient
varies, so the stage2 residual is weighted accordingly, using the
 lowcomplexity weighting function proposed in .
+ lowcomplexity Inverse Harmonic Mean Weighting (IHMW) function proposed in
+ .
The weights are derived directly from the stage1 codebook vector.
Let cb1_Q8[k] be the kth entry of the stage1
 codebook vector from or
+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:
@@ 1916,17 +2331,19 @@ 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.
+ tabulated and stored as 13bit unsigned values (with a range of 1819 to 5227,
+ inclusive) to avoid computing them when decoding.
+The reference implementation already requires code to compute these weights on
+ unquantized coefficients in the encoder, in silk_NLSF_VQ_weights_laroia()
+ (silk_NLSF_VQ_weights_laroia.c) and its callers, so it reuses that code in the
+ decoder instead of using a precomputed table to reduce the amount of ROM
+ required.
I1
Codebook
+Codebook (Q8) 0 1 2 3 4 5 6 7 8 90
@@ 1998,7 +2415,7 @@ The reference implementation computes them on the fly in
I1
Codebook
+Codebook (Q8) 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 150
@@ 2077,14 +2494,17 @@ NLSF_Q15[k] = (cb1_Q8[k]<<7) + (res_Q10[k]<<14)/w_Q9[k] ,
]]>
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.
+However, nothing in either the reconstruction process or the
+ quantization process in the encoder thus far guarantees that the coefficients
+ are monotonically increasing and separated well enough to ensure a stable
+ filter.
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
@@ 2163,12 +2583,12 @@ center_freq_Q15 = clamp(min_center_Q15[i],
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.
+Then the procedure repeats again, until it has either executed 20 times or
+ has stopped because the coefficients satisfy all the constraints.
After the 20th repetition of the above, the following fallback procedure
 executes once.
+After the 20th repetition of the above procedure, the following fallback
+ procedure executes once.
First, the values of NLSF_Q15[k] for 0 <= k < d_LPC
are sorted in ascending order.
Then for each value of k from 0 to d_LPC1, NLSF_Q15[k] is set to
@@ 2190,8 +2610,9 @@ min(NLSF_Q15[k], NLSF_Q15[k+1]  NDeltaMin_Q15[k+1]) .
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.
+ subframes) may use normalized LSF coefficients that are interpolated between
+ the decoded LSFs for the most recent coded frame (in the same channel) and the
+ current frame.
A Q2 interpolation factor follows the LSF coefficient indices in the bitstream,
which is decoded using the PDF in .
This happens in silk_decode_indices() (silk_decode_indices.c).
@@ 2224,7 +2645,7 @@ This interpolation is performed in silk_decode_parameters()
+ title="Converting Normalized LSFs to LPC Coefficients">
Any LPC filter A(z) can be split into a symmetric part P(z) and an
antisymmetric part Q(z) such that
@@ 2277,7 +2698,7 @@ 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
+ rather than the true inverse of the cosine function, when deriving the
normalized LSF coefficients.
@@ 2422,7 +2843,7 @@ The promotion of the expression from Q16 to Q17 implicitly scales the result

The a32_Q17[] coefficients are too large to fit in a 16bit value, which
@@ 2436,7 +2857,7 @@ 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.
+ is largest, breaking ties by choosing the lowest value of k.
Then, it computes the corresponding Q12 precision value, maxabs_Q12, subject to
an upper bound to avoid overflow in subsequent computations:
@@ 2460,7 +2881,7 @@ This is an approximation of the chirp factor needed to reduce the target
too large.
silk_bwexpander_32() (silk_bwexpander_32.c) peforms the bandwidth expansion
+silk_bwexpander_32() (silk_bwexpander_32.c) performs the bandwidth expansion
(again, only when maxabs_Q12 is greater than 32767) using the following
recurrence:
@@ 2489,14 +2910,15 @@ a32_Q17[k] = clamp(32768, (a32_Q17[k]+16) >> 5, 32767) << 5 .
Because this performs the actual saturation in the Q12 domain, but converts the
coefficients back to the Q17 domain for the purposes of prediction gain
limiting, this step must be performed after the 10th round of bandwidth
 expansion, regardless of whether or not the Q12 version of any of the
 coefficients still overflow a 16bit integer.
+ expansion, regardless of whether or not the Q12 version of any coefficient
+ still overflows a 16bit integer.
This saturation is not performed if maxabs_Q12 drops to 32767 or less prior to
the 10th round.

+
Even if the Q12 coefficients would fit, the resulting filter may still have a
significant gain (especially for voiced sounds), making the filter unstable.
@@ 2585,7 +3007,7 @@ Every multiply in this procedure except the one used to compute mul_Q16[k]
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.
+ 0 <= k < d_LPC, then the filter is considered stable.
On round i, 1 <= i <= 18, if the filter passes this
@@ 2597,7 +3019,7 @@ a_Q12[k] = (a32_Q17[k] + 16) >> 5 .
]]>
Otherwise, a round of bandwidth expansion is applied using the same procedure
 as in , with
+ as in , with

+
After the normalized LSF indices and, for 20 ms frames, the LSF
interpolation index, voiced frames (see )
@@ 2620,14 +3043,19 @@ There is one primary lag index for each SILK frame, but this is refined to
Each subframe also gets its own prediction gain coefficient.

+
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.
+ previous LBRR frame was not coded, and the first regular SILK frame in each
+ channel of an Opus frame all code the pitch lag as an absolute index.
+When the most recent coded frame in the current channel was not voiced, this
+ also forces absolute coding.
+In particular, unlike an LBRR frame where the previous frame is not coded, in a
+ 60 ms stereo Opus frame, if the first and third regular SILK frames
+ in the side channel are coded, voiced frames, but the second is not coded, the
+ third still uses relative coding.
With absolute coding, the primary pitch lag may range from 2 ms
@@ 2682,8 +3110,8 @@ Otherwise, the final primary pitch lag is then
lag = lag_prev + (delta_lag_index  9)
]]>
 where lag_prev is the primary pitch lag from the previous frame and
 delta_lag_index is the value just decoded.
+ where lag_prev is the primary pitch lag from the most recent frame in the same
+ channel and delta_lag_index is the value just decoded.
This allows a 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
@@ 2693,7 +3121,7 @@ However, because an Opus frame can use relative coding for at most two
+ title="PDF for Primary Pitch Lag Change">
PDF{46, 2, 2, 3, 4, 6, 10, 15,
26, 38, 30, 22, 15, 10, 7, 6,
@@ 2717,105 +3145,106 @@ The codebook index is decoded using one of the PDFs in
title="PDFs for Subframe Pitch Contour">
Audio BandwidthSILK Frame Size
+Codebook SizePDF
NB10 ms
+NB10 ms3{143, 50, 63}/256
NB20 ms
+NB20 ms11{68, 12, 21, 17, 19, 22, 30, 24,
17, 16, 10}/256
MB or WB10 ms
+MB or WB10 ms12{91, 46, 39, 19, 14, 12, 8, 7,
6, 5, 5, 4}/256
MB or WB20 ms
+MB or WB20 ms34{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}
+ 1, 1}/256IndexSubframe Offsets
0 0, 0
1 1, 0
2 0, 1
+0 0 0
+1 1 0
+2 0 1IndexSubframe Offsets
 0 0, 0, 0, 0
 1 2, 1, 0, 1
 21, 0, 1, 2
 31, 0, 0, 1
 41, 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
+ 0 0 0 0 0
+ 1 2 1 0 1
+ 21 0 1 2
+ 31 0 0 1
+ 41 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 1IndexSubframe Offsets
 0 0, 0
 1 0, 1
 2 1, 0
 31, 1
 4 1, 1
 51, 2
 6 2, 1
 72, 2
 8 2, 2
 92, 3
10 3, 2
113, 3
+ 0 0 0
+ 1 0 1
+ 2 1 0
+ 31 1
+ 4 1 1
+ 51 2
+ 6 2 1
+ 72 2
+ 8 2 2
+ 92 3
+10 3 2
+113 3IndexSubframe Offsets
 0 0, 0, 0, 0
 1 0, 0, 1, 1
 2 1, 1, 0, 0
 31, 0, 0, 0
 4 0, 0, 0, 1
 5 1, 0, 0, 0
 61, 0, 0, 1
 7 0, 0, 0, 1
 81, 0, 1, 2
 9 1, 0, 0, 1
102, 1, 1, 2
11 2, 1, 0, 1
122, 0, 0, 2
132, 0, 1, 3
14 2, 1, 1, 2
153, 1, 1, 3
16 2, 0, 0, 2
17 3, 1, 0, 2
183, 1, 2, 4
194, 1, 1, 4
20 3, 1, 1, 3
214, 1, 2, 5
22 4, 2, 1, 3
23 4, 1, 1, 4
245, 1, 2, 6
25 5, 2, 1, 4
266, 2, 2, 6
275, 2, 2, 5
28 6, 2, 1, 5
297, 2, 3, 8
30 6, 2, 2, 6
31 5, 2, 2, 5
32 8, 3, 2, 7
339, 3, 3, 9
+ 0 0 0 0 0
+ 1 0 0 1 1
+ 2 1 1 0 0
+ 31 0 0 0
+ 4 0 0 0 1
+ 5 1 0 0 0
+ 61 0 0 1
+ 7 0 0 0 1
+ 81 0 1 2
+ 9 1 0 0 1
+102 1 1 2
+11 2 1 0 1
+122 0 0 2
+132 0 1 3
+14 2 1 1 2
+153 1 1 3
+16 2 0 0 2
+17 3 1 0 2
+183 1 2 4
+194 1 1 4
+20 3 1 1 3
+214 1 2 5
+22 4 2 1 3
+23 4 1 1 4
+245 1 2 6
+25 5 2 1 4
+266 2 2 6
+275 2 2 5
+28 6 2 1 5
+297 2 3 8
+30 6 2 2 6
+31 5 2 2 5
+32 8 3 2 7
+339 3 3 9
@@ 2823,8 +3252,8 @@ 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
 kth subframe.
+ entry of the codebook from the appropriate table given above for the k'th
+ subframe.
Then the final pitch lag for that subframe is





+
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.
+SILK can use a separate 5tap pitch filter for each subframe.
+It selects the filter to use from one of three codebooks.
+The three codebooks each represent different ratedistortion tradeoffs, with
+ average rates of 1.61 bits/subframe, 3.68 bits/subframe, and
+ 4.85 bits/subframe, respectively.






The CELT layer is decoded based on the following symbols and sets of symbols:
+The importance of the filter coefficients generally depends on two factors: the
+ periodicity of the signal and relative energy between the current subframe and
+ the signal from one period earlier.
+Greater periodicity and decaying energy both lead to more important filter
+ coefficients, and thus should be coded with lower distortion and higher rate.
+These properties are relatively stable over the duration of a single SILK
+ frame, hence all of the subframes in a SILK frame must choose their filter
+ from the same codebook.
+This is signaled with an explicitlycoded "periodicity index".
+This immediately follows the subframe pitch lags, and is coded using the
+ 3entry PDF from .

Symbol(s)
PDF
Condition
silence{32767, 1}/32768
postfilter{1, 1}/2
octaveuniform (6)postfilter
periodraw bits (4+octave)postfilter
gainraw bits (3)postfilter
tapset{2, 1, 1}/4postfilter
transient{7, 1}/8
intra{7, 1}/8
coarse energy
tf_change
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{1, 1}/2
intensityuniform
dual{1, 1}/2
fine energy
residual
anticollapse{1, 1}/2
finalize
Order of the symbols in the CELT section of the bitstream.
+
+PDF
+{77, 80, 99}/256
The decoder extracts information from the rangecoded bitstream in the order
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,
decoding, or transmission and SHOULD take measures to conceal the error and/or report
to the application that a problem has occurred.
+The index of the filter to use for each subframe follows.
+They are all coded using the PDF from
+ corresponding to the periodicity index.
+ through
+ contain the corresponding filter taps
+ as signed Q7 integers.


The transient flag encoded in the bitstream has a
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
change in tf resolution is defined in tf_select_table[][] in celt.c and depends
on the frame size, whether the transient flag is set, and the value of tf_select.
The tf_select flag uses a 1/2 probability, but is only decoded
if it can have an impact on the result knowing the value of all perband
tf_change flags.


+
+Periodicity Index
+Codebook Size
+PDF
+08{185, 15, 13, 13, 9, 9, 6, 6}/256
+116{57, 34, 21, 20, 15, 13, 12, 13,
+ 10, 10, 9, 10, 9, 8, 7, 8}/256
+232{15, 16, 14, 12, 12, 12, 11, 11,
+ 11, 10, 9, 9, 9, 9, 8, 8,
+ 8, 8, 7, 7, 6, 6, 5, 4,
+ 5, 4, 4, 4, 3, 4, 3, 2}/256
+

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

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


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)
+
+Index
+Filter Taps (Q7)
+ 0
+ 6 27 61 39 5
+ 1
+11 42 88 4 1
+ 2
+ 2 60 65 6 4
+ 3
+ 1 5 73 56 1
+ 4
+ 9 19 94 29 9
+ 5
+ 0 12 99 6 4
+ 6
+ 8 19 102 46 13
+ 7
+ 3 2 13 3 2
+ 8
+ 9 21 84 72 18
+ 9
+11 46 104 22 8
+10
+ 18 38 48 23 0
+11
+16 70 83 21 11
+12
+ 5 11 117 22 8
+13
+ 6 23 117 12 3
+14
+ 3 8 95 28 4
+15
+10 15 77 60 15
+16
+ 1 4 124 2 4
+17
+ 3 38 84 24 25
+18
+ 2 13 42 13 31
+19
+ 21 4 56 46 1
+20
+ 1 35 79 13 19
+21
+ 7 65 88 9 14
+22
+ 20 4 81 49 29
+23
+ 20 0 75 3 17
+24
+ 5 9 44 92 8
+25
+ 1 3 22 69 31
+26
+ 6 95 41 12 5
+27
+ 39 67 16 4 1
+28
+ 0 6 120 55 36
+29
+13 44 122 4 24
+30
+ 81 5 11 3 7
+31
+ 2 0 9 10 88
+
+
+
+
+
+
+In some circumstances an LTP scaling parameter appears after the LTP filter
+ coefficients.
+This allows the encoder to trade off the prediction gain between
+ packets against the recovery time after packet loss.
+Like the quantization gains, only the first LBRR frame in an Opus frame,
+ an LBRR frame where the prior LBRR frame was not coded, and the first regular
+ SILK frame in each channel of an Opus frame include this field, and, like all
+ of the other LTP parameters, only for frames that are also voiced.
+Unlike absolutecoding for pitch lags, a regular SILK frame other than the
+ first one in a channel will not include this field even if the prior frame was
+ not voiced.
+
+
+If present, the value is coded using the 3entry PDF in
+ .
+The three possible values represent Q14 scale factors of 15565, 12288, and
+ 8192, respectively (corresponding to approximately 0.95, 0.75, and 0.5).
+Frames that do not code the scaling parameter use the default factor of 15565
+ (approximately 0.95).
+
+
+
+PDF
+{128, 64, 64}/256
+
+
+
+
+
+
+
+
+SILK uses a linear congruential generator (LCG) to inject pseudorandom noise
+ into the quantized excitation.
+To ensure synchronization of this process between the encoder and decoder, each
+ SILK frame stores a 2bit seed after the LTP parameters (if any).
+The encoder may consider the choice of this seed during quantization, meaning
+ the flexibility to choose the LCG seed can reduce distortion.
+The seed is decoded with the uniform 4entry PDF in
+ , yielding a value between 0 and 3, inclusive.
+
+
+
+PDF
+{64, 64, 64, 64}/256
+
+
+
+
+
+
+SILK codes the excitation using a modified version of the Pyramid Vector
+ Quantization (PVQ) codebook .
+The PVQ codebook is designed for Laplacedistributed values and consists of all
+ sums of K signed, unit pulses in a vector of dimension N, where two pulses at
+ the same position are required to have the same sign.
+Thus the codebook includes all integer codevectors y of dimension N that
+ satisfy
+
+
+
+Unlike regular PVQ, SILK uses a variablelength, rather than fixedlength,
+ encoding.
+This encoding is better suited to the more Gaussianlike distribution of the
+ coefficient magnitudes and the nonuniform distribution of their signs (caused
+ by the quantization offset described below).
+SILK also handles large codebooks by coding the least significant bits (LSb's)
+ of each coefficient directly.
+This adds a small coding efficiency loss, but greatly reduces the computation
+ time and ROM size required for decoding, as implemented in
+ silk_decode_pulses() (silk_decode_pulses.c).
+
+
+
+SILK fixes the dimension of the codebook to N = 16.
+The excitation is made up of a number of "shell blocks", each 16 samples in
+ size.
+ lists the number of shell blocks
+ required for a SILK frame for each possible audio bandwidth and frame size.
+10 ms MB frames nominally contain 120 samples (10 ms at
+ 12 kHz), which is not a multiple of 16.
+This is handled by coding 8 shell blocks (128 samples) and discarding the final
+ 8 samples of the last block.
+The decoder contains no special case that prevents an encoder from placing
+ pulses in these samples, and they must be correctly parsed from the bitstream
+ if present, but they are otherwise ignored.
+
+
+
+Audio Bandwidth
+Frame Size
+Number of Shell Blocks
+NB10 ms5
+MB10 ms8
+WB10 ms10
+NB20 ms10
+MB20 ms15
+WB20 ms20
+
+
+
+
+The first symbol in the excitation is a "rate level", which is an index from 0
+ to 8, inclusive, coded using the PDF in
+ corresponding to the signal type of the current frame (from
+ ).
+The rate level selects the PDF used to decode the number of pulses in
+ the individual shell blocks.
+It does not directly convey any information about the bitrate or the number of
+ pulses itself, but merely changes the probability of the symbols in
+ .
+Level 0 provides a more efficient encoding at low rates generally, and
+ level 8 provides a more efficient encoding at high rates generally,
+ though the most efficient level for a particular SILK frame may depend on the
+ exact distribution of the coded symbols.
+An encoder should, but is not required to, use the most efficient rate level.
+
+
+
+Signal Type
+PDF
+Inactive or Unvoiced
+{15, 51, 12, 46, 45, 13, 33, 27, 14}/256
+Voiced
+{33, 30, 36, 17, 34, 49, 18, 21, 18}/256
+
+
+
+
+
+
+The total number of pulses in each of the shell blocks follows the rate level.
+The pulse counts for all of the shell blocks are coded consecutively, before
+ the content of any of the blocks.
+Each block may have anywhere from 0 to 16 pulses, inclusive, coded using the
+ 18entry PDF in corresponding to the
+ rate level from .
+The special value 17 indicates that this block has one or more additional
+ LSb's to decode for each coefficient.
+If the decoder encounters this value, it decodes another value for the actual
+ pulse count of the block, but uses the PDF corresponding to the special rate
+ level 9 instead of the normal rate level.
+This process repeats until the decoder reads a value less than 17, and it then
+ sets the number of extra LSb's used to the number of 17's decoded for that
+ block.
+If it reads the value 17 ten times, then the next iteration uses the special
+ rate level 10 instead of 9.
+The probability of decoding a 17 when using the PDF for rate level 10 is
+ zero, ensuring that the number of LSb's for a block will not exceed 10.
+The cumulative distribution for rate level 10 is just a shifted version of
+ that for 9 and thus does not require any additional storage.
+
+
+
+Rate Level
+PDF
+0
+{131, 74, 25, 8, 3, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}/256
+1
+{58, 93, 60, 23, 7, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}/256
+2
+{43, 51, 46, 33, 24, 16, 11, 8, 6, 3, 3, 3, 2, 1, 1, 2, 1, 2}/256
+3
+{17, 52, 71, 57, 31, 12, 5, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}/256
+4
+{6, 21, 41, 53, 49, 35, 21, 11, 6, 3, 2, 2, 1, 1, 1, 1, 1, 1}/256
+5
+{7, 14, 22, 28, 29, 28, 25, 20, 17, 13, 11, 9, 7, 5, 4, 4, 3, 10}/256
+6
+{2, 5, 14, 29, 42, 46, 41, 31, 19, 11, 6, 3, 2, 1, 1, 1, 1, 1}/256
+7
+{1, 2, 4, 10, 19, 29, 35, 37, 34, 28, 20, 14, 8, 5, 4, 2, 2, 2}/256
+8
+{1, 2, 2, 5, 9, 14, 20, 24, 27, 28, 26, 23, 20, 15, 11, 8, 6, 15}/256
+9
+{1, 1, 1, 6, 27, 58, 56, 39, 25, 14, 10, 6, 3, 3, 2, 1, 1, 2}/256
+10
+{2, 1, 6, 27, 58, 56, 39, 25, 14, 10, 6, 3, 3, 2, 1, 1, 2, 0}/256
+
+
+
+
+
+
+The locations of the pulses in each shell block follows the pulse counts,
+ as decoded by silk_shell_decoder() (silk_shell_coder.c).
+As with the pulse counts, these locations are coded for all the shell blocks
+ before any of the remaining information for each block.
+Unlike many other codecs, SILK places no restriction on the distribution of
+ pulses within a shell block.
+All of the pulses may be placed in a single location, or each one in a unique
+ location, or anything in between.
+
+
+
+The location of pulses is coded by recursively partitioning each block into
+ halves, and coding how many pulses fall on the left side of the split.
+All remaining pulses must fall on the right side of the split.
+The process then recurses into the left half, and after that returns, the
+ right half (preorder traversal).
+The PDF to use is chosen by the size of the current partition (16, 8, 4, or 2)
+ and the number of pulses in the partition (1 to 16, inclusive).
+ through
+ list the PDFs used for each partition
+ size and pulse count.
+This process skips partitions without any pulses, i.e., where the initial pulse
+ count from was zero, or where the split in
+ the prior level indicated that all of the pulses fell on the other side.
+These partitions have nothing to code, so they require no PDF.
+
+
+
+Pulse Count
+PDF
+ 1{126, 130}/256
+ 2{56, 142, 58}/256
+ 3{25, 101, 104, 26}/256
+ 4{12, 60, 108, 64, 12}/256
+ 5{7, 35, 84, 87, 37, 6}/256
+ 6{4, 20, 59, 86, 63, 21, 3}/256
+ 7{3, 12, 38, 72, 75, 42, 12, 2}/256
+ 8{2, 8, 25, 54, 73, 59, 27, 7, 1}/256
+ 9{2, 5, 17, 39, 63, 65, 42, 18, 4, 1}/256
+10{1, 4, 12, 28, 49, 63, 54, 30, 11, 3, 1}/256
+11{1, 4, 8, 20, 37, 55, 57, 41, 22, 8, 2, 1}/256
+12{1, 3, 7, 15, 28, 44, 53, 48, 33, 16, 6, 1, 1}/256
+13{1, 2, 6, 12, 21, 35, 47, 48, 40, 25, 12, 5, 1, 1}/256
+14{1, 1, 4, 10, 17, 27, 37, 47, 43, 33, 21, 9, 4, 1, 1}/256
+15{1, 1, 1, 8, 14, 22, 33, 40, 43, 38, 28, 16, 8, 1, 1, 1}/256
+16{1, 1, 1, 1, 13, 18, 27, 36, 41, 41, 34, 24, 14, 1, 1, 1, 1}/256
+
+
+
+Pulse Count
+PDF
+ 1{127, 129}/256
+ 2{53, 149, 54}/256
+ 3{22, 105, 106, 23}/256
+ 4{11, 61, 111, 63, 10}/256
+ 5{6, 35, 86, 88, 36, 5}/256
+ 6{4, 20, 59, 87, 62, 21, 3}/256
+ 7{3, 13, 40, 71, 73, 41, 13, 2}/256
+ 8{3, 9, 27, 53, 70, 56, 28, 9, 1}/256
+ 9{3, 8, 19, 37, 57, 61, 44, 20, 6, 1}/256
+10{3, 7, 15, 28, 44, 54, 49, 33, 17, 5, 1}/256
+11{1, 7, 13, 22, 34, 46, 48, 38, 28, 14, 4, 1}/256
+12{1, 1, 11, 22, 27, 35, 42, 47, 33, 25, 10, 1, 1}/256
+13{1, 1, 6, 14, 26, 37, 43, 43, 37, 26, 14, 6, 1, 1}/256
+14{1, 1, 4, 10, 20, 31, 40, 42, 40, 31, 20, 10, 4, 1, 1}/256
+15{1, 1, 3, 8, 16, 26, 35, 38, 38, 35, 26, 16, 8, 3, 1, 1}/256
+16{1, 1, 2, 6, 12, 21, 30, 36, 38, 36, 30, 21, 12, 6, 2, 1, 1}/256
+
+
+
+Pulse Count
+PDF
+ 1{127, 129}/256
+ 2{49, 157, 50}/256
+ 3{20, 107, 109, 20}/256
+ 4{11, 60, 113, 62, 10}/256
+ 5{7, 36, 84, 87, 36, 6}/256
+ 6{6, 24, 57, 82, 60, 23, 4}/256
+ 7{5, 18, 39, 64, 68, 42, 16, 4}/256
+ 8{6, 14, 29, 47, 61, 52, 30, 14, 3}/256
+ 9{1, 15, 23, 35, 51, 50, 40, 30, 10, 1}/256
+10{1, 1, 21, 32, 42, 52, 46, 41, 18, 1, 1}/256
+11{1, 6, 16, 27, 36, 42, 42, 36, 27, 16, 6, 1}/256
+12{1, 5, 12, 21, 31, 38, 40, 38, 31, 21, 12, 5, 1}/256
+13{1, 3, 9, 17, 26, 34, 38, 38, 34, 26, 17, 9, 3, 1}/256
+14{1, 3, 7, 14, 22, 29, 34, 36, 34, 29, 22, 14, 7, 3, 1}/256
+15{1, 2, 5, 11, 18, 25, 31, 35, 35, 31, 25, 18, 11, 5, 2, 1}/256
+16{1, 1, 4, 9, 15, 21, 28, 32, 34, 32, 28, 21, 15, 9, 4, 1, 1}/256
+
+
+
+Pulse Count
+PDF
+ 1{128, 128}/256
+ 2{42, 172, 42}/256
+ 3{21, 107, 107, 21}/256
+ 4{12, 60, 112, 61, 11}/256
+ 5{8, 34, 86, 86, 35, 7}/256
+ 6{8, 23, 55, 90, 55, 20, 5}/256
+ 7{5, 15, 38, 72, 72, 36, 15, 3}/256
+ 8{6, 12, 27, 52, 77, 47, 20, 10, 5}/256
+ 9{6, 19, 28, 35, 40, 40, 35, 28, 19, 6}/256
+10{4, 14, 22, 31, 37, 40, 37, 31, 22, 14, 4}/256
+11{3, 10, 18, 26, 33, 38, 38, 33, 26, 18, 10, 3}/256
+12{2, 8, 13, 21, 29, 36, 38, 36, 29, 21, 13, 8, 2}/256
+13{1, 5, 10, 17, 25, 32, 38, 38, 32, 25, 17, 10, 5, 1}/256
+14{1, 4, 7, 13, 21, 29, 35, 36, 35, 29, 21, 13, 7, 4, 1}/256
+15{1, 2, 5, 10, 17, 25, 32, 36, 36, 32, 25, 17, 10, 5, 2, 1}/256
+16{1, 2, 4, 7, 13, 21, 28, 34, 36, 34, 28, 21, 13, 7, 4, 2, 1}/256
+
+
+
+
+
+
+After the decoder reads the pulse locations for all blocks, it reads the LSb's
+ (if any) for each block in turn.
+Inside each block, it reads all the LSb's for each coefficient in turn, even
+ those where no pulses were allocated, before proceeding to the next one.
+They are coded from most significant to least significant, and they all use the
+ PDF in .
+
+
+
+PDF
+{136, 120}/256
+
+
+
+The number of LSb's read for each coefficient in a block is determined in
+ .
+The magnitude of the coefficient is initially equal to the number of pulses
+ placed at that location in .
+As each LSb is decoded, the magnitude is doubled, and then the value of the LSb
+ added to it, to obtain an updated magnitude.
+
+
+
+
+
+After decoding the pulse locations and the LSb's, the decoder knows the
+ magnitude of each coefficient in the excitation.
+It then decodes a sign for all coefficients with a nonzero magnitude, using
+ one of the PDFs from .
+If the value decoded is 0, then the coefficient magnitude is negated.
+Otherwise, it remains positive.
+
+
+
+The decoder chooses the PDF for the sign based on the signal type and
+ quantization offset type (from ) and the
+ number of pulses in the block (from ).
+The number of pulses in the block does not take into account any LSb's.
+If a block has no pulses, even if it has some LSb's (and thus may have some
+ nonzero coefficients), then no signs are decoded.
+In that case, any nonzero coefficients use a positive sign.
+
+
+
+Signal Type
+Quantization Offset Type
+Pulse Count
+PDF
+InactiveLow1{207, 49}/256
+InactiveLow2{189, 67}/256
+InactiveLow3{179, 77}/256
+InactiveLow4{174, 82}/256
+InactiveLow5{163, 93}/256
+InactiveLow6 or more{157, 99}/256
+InactiveHigh1{245, 11}/256
+InactiveHigh2{238, 18}/256
+InactiveHigh3{232, 24}/256
+InactiveHigh4{225, 31}/256
+InactiveHigh5{220, 36}/256
+InactiveHigh6 or more{211, 45}/256
+UnvoicedLow1{210, 46}/256
+UnvoicedLow2{190, 66}/256
+UnvoicedLow3{178, 78}/256
+UnvoicedLow4{169, 87}/256
+UnvoicedLow5{162, 94}/256
+UnvoicedLow6 or more{152, 104}/256
+UnvoicedHigh1{242, 14}/256
+UnvoicedHigh2{235, 21}/256
+UnvoicedHigh3{224, 32}/256
+UnvoicedHigh4{214, 42}/256
+UnvoicedHigh5{205, 51}/256
+UnvoicedHigh6 or more{190, 66}/256
+VoicedLow1{162, 94}/256
+VoicedLow2{152, 104}/256
+VoicedLow3{147, 109}/256
+VoicedLow4{144, 112}/256
+VoicedLow5{141, 115}/256
+VoicedLow6 or more{138, 118}/256
+VoicedHigh1{203, 53}/256
+VoicedHigh2{187, 69}/256
+VoicedHigh3{176, 80}/256
+VoicedHigh4{168, 88}/256
+VoicedHigh5{161, 95}/256
+VoicedHigh6 or more{154, 102}/256
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+The CELT layer is decoded based on the following symbols and sets of symbols:
+
+
+
+Symbol(s)
+PDF
+Condition
+silence{32767, 1}/32768
+postfilter{1, 1}/2
+octaveuniform (6)postfilter
+periodraw bits (4+octave)postfilter
+gainraw bits (3)postfilter
+tapset{2, 1, 1}/4postfilter
+transient{7, 1}/8
+intra{7, 1}/8
+coarse energy
+tf_change
+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{1, 1}/2
+intensityuniform
+dual{1, 1}/2
+fine energy
+residual
+anticollapse{1, 1}/2
+finalize
+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
+possible for a decoded value to be out of range due to a very small amount of redundancy
+in the encoding of large integers by the range coder.
+In that case, the decoder should assume there has been an error in the coding,
+decoding, or transmission and SHOULD take measures to conceal the error and/or report
+to the application that a problem has occurred.
+
+
+
+
+The "transient" flag encoded in the bitstream has a 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
+change in tf resolution is defined in tf_select_table[][] in celt.c and depends
+on the frame size, whether the transient flag is set, and the value of tf_select.
+The tf_select flag uses a 1/2 probability, but is only decoded
+if it can have an impact on the result knowing the value of all perband
+tf_change flags.
+
+
+
+
+
+
+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
+
+
+
+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:
+
+
+
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
+applied depend on the frame size in use when not using intra energy and are alpha=0, beta=4915/32768
when using intra energy.
The 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.
+limited dynamic range do 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
+with separate 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).
@@ 2958,19 +3975,19 @@ implemented in ec_laplace_decode() (laplace.c).
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
+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).
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.
+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.
+starting from band 0. If any bits are left after this, they are left unused.
This is implemented in unquant_energy_finalise() (quant_bands.c).
@@ 2988,35 +4005,35 @@ selected to achieve the desired rate constraints.
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
+two factors: that 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
+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
+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
+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
+packet sizes expressed by a higherlevel 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
+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
@@ 3026,7 +4043,7 @@ mechanisms are provided to alter the implicit allocation:Band boostAllocation trim
band skipping
+Band skipping
@@ 3036,58 +4053,58 @@ biasing the overall allocation towards higher or lower frequency bands. The thir
skipping, selects which lowprecision high frequency bands
will be allocated no shape bits at all.
In stereo mode there are also two additional parameters
+In stereo mode there are two additional parameters
potentially coded as part of the allocation procedure: a parameter to allow the
selective elimination of allocation for the 'side' 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
+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
+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
+parameters. As with other signaled parameters, an encoder is free to choose the
+values in any manner, but unless a technique is known to deliver superior
perceptual results the methods used by the reference implementation should be
used.
The process of allocation consists of the following steps: determining the perband
+The allocation process 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
+the remaining capacity of the frame, searching the mode table for the
entry nearest but not exceeding the available space (subject to the tilt, boosts, band
maximums, and band minimums), linear interpolation, reallocation of
unused bits with concurrent skip decoding, determination of the
fineenergy vs shape split, and final reallocation. This process results
in an shape allocation perband (in 1/8th bit units), a perband fineenergy
+fineenergy vs. shape split, and final reallocation. This process results
+in a perband shape allocation (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
+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
+that can be used by each band for a given mode. The value is
approximate because the shape encoding is variable rate (due
to entropy coding of splitting parameters). Setting the maximum too low reduces the
maximum achievable quality in a band while setting it too high
may result in waste: bitstream capacity available at the end
+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
+the maximums are provided in 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 convert the values in cache.caps into the actual maximums: first
+set nbBands to the maximum number of bands for this mode, and stereo to
+zero if stereo is not in use and one otherwise. For each band set N
to the number of MDCT bins covered by the band (for one channel), set LM
to the shift value for the frame size (e.g. 0 for 120, 1 for 240, 3 for 480)
+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
+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.
+cap[]. The elements fit in signed 16bit integers but do not fit in 8 bits.
This procedure is implemented in the reference in the function init_caps() in celt.c.
@@ 3098,15 +4115,15 @@ 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)).
+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
+size of the frame in 8th bits, 'total_boost' to zero, and 'tell' to the total number
of 8th bits decoded
so far. For each band from the coding start (0 normally, but 17 in hybrid mode)
to the coding end (which changes depending on the signaled bandwidth): Set 'width'
+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
@@ 3118,16 +4135,16 @@ 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 greater than 2, decrease dynalloc_logp. Once this process has been
+executed on all bands, the band boosts have been decoded. This procedure
is implemented around line 2352 of celt.c.
At very low rates it's possible that there won't be enough available
+At very low rates it is possible that there won't be enough available
space to execute the inner loop even once. In these cases band boost
is not possible but its overhead is completely eliminated. Because of the
high cost of band boost when activated a reasonable encoder should not be
+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
+logic around line 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
@@ 3135,48 +4152,48 @@ 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)
+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
+bits minus total_boost (a product of the above band boost procedure),
decode the trim value using the inverse CDF {127, 126, 124, 119, 109, 87, 41, 19, 9, 4, 2, 0}.Stereo parametersAnticollapse 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'
+The allocation computation begins by setting up some initial conditions.
+'total' is set to the remaining available 8th bits, computed by taking the
+size of the coded frame times 8 and subtracting ec_tell_frac(). From this value, one (8th bit)
+is subtracted to ensure that the resulting allocation will be conservative. 'anti_collapse_rsv'
is set to 8 (8th bits) 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
+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
+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
+process, but very low rate allocations produce an excessively sparse spectrum and these bands
+are better served by having no allocation at all. For each coded band, set thresh[band] to
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
+or 48 128th bits per MDCT bin, whichever is greater. The bandsize 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
+'trim_offsets[]'. For each coded band take the alloc_trim and subtract 5 and LM. Then multiply
+the result by the number of channels, the number of MDCT bins in the shortest frame size for this mode,
+the number of remaining bands, 2**LM, and 8. 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.
@@ 3184,8 +4201,8 @@ from the coarse energy coding.
In each band, the normalized shape is encoded
using a vector quantization scheme called a "Pyramid vector quantizer".
+In each band, the normalized "shape" is encoded
+using a vector quantization scheme called a "pyramid vector quantizer".
In
@@ 3203,15 +4220,15 @@ This index is converted into the corresponding vector as explained in
Although the allocation is performed in 1/8th bit units, the quantization requires
an integer number of pulses K. To do this, the encoder searches for the value
of K that produces the number of bits that is the nearest to the allocated value
(rounding down if exactly halfway between two values), subject to not exceeding
the total number of bits available. For efficiency reasons the search is performed against a
precomputated allocation table which only permits some K values for each N. The number of
codebooks entries can be computed as explained in . The difference
+of K that produces the number of bits nearest to the allocated value
+(rounding down if exactly halfway between two values), not to exceed
+the total number of bits available. For efficiency reasons, the search is performed against a
+precomputed allocation table which only permits some K values for each N. The number of
+codebook entries can be computed as explained in . The difference
between the number of bits allocated and the number of bits used is accumulated to a
balance (initialised to zero) that helps adjusting the
+"balance" (initialized to zero) that helps adjust the
allocation for the next bands. One third of the balance is applied to the
bit allocation of the each band to help achieving the target allocation. The only
+bit allocation of each band to help achieve the target allocation. The only
exceptions are the band before the last and the last band, for which half the balance
and the whole balance are applied, respectively.
@@ 3222,17 +4239,17 @@ 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 codeword is converted from a unique index in the same way 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
+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
+univariate recurrence to initialize 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
@@ 3242,12 +4259,60 @@ they are equivalent to the mathematical definition.
The decoding of the codeword from the index is performed as specified in
, as implemented in function
decode_pulses() (cwrs.c).
+decode_pulses() (cwrs.c). The decoded codeword is then normalised such that it's
+L2norm equals one.
+The normalised vector decoded in is then rotated
+for the purpose of avoiding tonal artefacts. The rotation gain is equal to
+
+
+
+
+where N is the number of dimensions, K is the number of pulses, and f_r depends on
+the value of the "spread" parameter in the bitstream.
+
+
+
+Spread value
+f_r
+ 0infinite (no rotation)
+ 115
+ 210
+ 35
+
+
+
+The rotation angle is then calculated as
+
+
+
+A 2D rotation R(i,j) between points x_i and x_j is defined as:
+
+
+
+
+An ND rotation is then achieved by applying a series of 2D rotations back and forth, in the
+following order: R(x_1, x_2), R(x_2, x_3), ..., R(x_N2, X_N1), R(x_N1, X_N),
+R(x_N2, X_N1), ..., R(x_1, x_2).
+
+
+
+If the decoded vector represents more
+than one time block, then the following process is applied separately on each time block.
@@ 3258,7 +4323,7 @@ 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
+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.
@@ 3277,7 +4342,7 @@ of stereo audio.
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
+When anticollapse is set, the energy in each small MDCT is prevented
from collapsing to zero. For each band of each MDCT where a collapse is
detected, a pseudorandom signal is inserted with an energy corresponding
to the min energy over the two previous frames. A renormalization step is
@@ 3296,13 +4361,37 @@ multiplied by the square root of the decoded energy. This is done by denormalise
+
+
+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.
+It is derived from a basic (full overlap) window that is the same as the one used in the Vorbis codec:
+
+
+
+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 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
as the encoder. The IMDCT and windowing are performed by mdct_backward
(mdct.c). If a timedomain preemphasis
window was applied in the encoder, the (inverse) timedomain deemphasis window
is applied on the IMDCT result.
+samples, while scaling by 1/2. A "lowoverlap" window is used to reduce the algorithmic delay.
+It is derived from a basic (full overlap) 240sample version of the window used by the Vorbis codec:
+
+
+
+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 IMDCT and
+windowing are performed by mdct_backward (mdct.c).
@@ 3316,7 +4405,7 @@ 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
+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,
@@ 3345,7 +4434,16 @@ 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
used in the encoder: 1/A(z)=1/(1alpha_p*z^1), where alpha_p=0.8500061035.
+used in the encoder:
+
+
+
+where alpha_p=0.8500061035.
@@ 3355,7 +4453,7 @@ 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
+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
@@ 3379,11 +4477,11 @@ 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
+transitions: with side information or without it. 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
+the gap or 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.
@@ 3393,35 +4491,35 @@ 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
+This frame is designed to fill in the gap or discontinuity without requiring
+the decoder to conceal it. For transitions 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
+needs to be decoded just after the SILK part of the bitstream. When the
+symbol value is 1, the frame then includes an embedded redundant frame. The
+redundant frame always starts and ends on a byte boundary. 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).
+is instead set to the same bandwidth of the current frame (for MB
+frames, the redundant frame is set to WB).
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
+the square of the MDCT powercomplementary 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.
+powercomplementary window.
@@ 3446,11 +4544,11 @@ Opus encoder block diagram.
 conversion   
audio  ++ ++  ++
+ +> Range 
  ++ encoder>
   CELT  +>  bitstream
 +>encoder+ ++
  
 ++
+  ++ ++ encoder>
+   Delay   CELT  +>  bitstream
+ +>Compensation>encoder+ ++
+    
+ ++ ++
]]>
@@ 3469,7 +4567,7 @@ used in three different ways, to encode:
The range encoder maintains an internal state vector composed of the
fourtuple (low,rng,rem,ext), representing the low end of the current
+fourtuple (low,rng,rem,ext) representing the low end of the current
range, the size of the current range, a single buffered output octet,
and a count of additional carrypropagating output octets. Both rng
and low are 32bit unsigned integer values, rem is an octet value or
@@ 3488,8 +4586,8 @@ we maintain the distinction here for clarity.
describing the range of the symbol to be encoded in the current
context, with 0 <= fl < fh <= ft <= 65535. The values of this tuple
are derived from the probability model for the symbol. Let f(i) be
 the frequency of the ith symbol in the current context. Then the
 threetuple corresponding to the kth symbol is given by
+ the frequency of the i'th symbol in the current context. Then the
+ threetuple corresponding to the k'th symbol is given by
@@ 3543,7 +4641,7 @@ 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 Voice Activity Detector (VAD) to produce a measure of voice activity, spectral tilt, and signaltonoise estimates for each frame. The VAD uses a sequence of halfband filterbanks to split the signal into four subbands: 0  Fs/16, Fs/16  Fs/8, Fs/8  Fs/4, and Fs/4  Fs/2, where Fs is the sampling frequency (8, 12, 16, or 24 kHz). The lowest subband, from 0  Fs/16, is highpass filtered with a firstorder moving average (MA) 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 a SignaltoNoise Ratio (SNR) value is computed as the logarithm of the ratio of energy to noise level. Using these intermediate variables, the following parameters are calculated for use in other SILK modules:
Average SNR. The average of the subband SNR values.
@@ 3702,7 +4800,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 Auto Regressive Moving Average (ARMA) 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.
@@ 3751,7 +4849,7 @@ fl=sum(f(i),iIn 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 an 8 kHz signal (downsampled from 12, 16, or 24 kHz) and measures time correlations only near the lags corresponding to those that had sufficiently high correlations in the first stage. The resulting correlations are adjusted for a small bias towards short lags to avoid ending up with a multiple of the true pitch lag. The highest adjusted correlation is compared to a threshold depending on:
Whether the previous frame was classified as voiced
@@ 3774,11 +4872,11 @@ fl=sum(f(i),i
 The noise shaping analysis finds gains and filter coefficients used in the prefilter and noise shaping quantizer. These parameters are chosen such that they will fulfil several requirements:
+ The noise shaping analysis finds gains and filter coefficients used in the prefilter and noise shaping quantizer. These parameters are chosen such that they will fulfill several requirements:
Balancing quantization noise and bitrate. The quantization gains determine the step size between reconstruction levels of the excitation signal. Therefore, increasing the quantization gain amplifies quantization noise, but also reduces the bitrate by lowering the entropy of the quantization indices.Spectral shaping of the quantization noise; the noise shaping quantizer is capable of reducing quantization noise in some parts of the spectrum at the cost of increased noise in other parts without substantially changing the bitrate. By shaping the noise such that it follows the signal spectrum, it becomes less audible. In practice, best results are obtained by making the shape of the noise spectrum slightly flatter than the signal spectrum.
 Deemphasizing spectral valleys; by using different coefficients in the analysis and synthesis part of the prefilter and noise shaping quantizer, the levels of the spectral valleys can be decreased relative to the levels of the spectral peaks such as speech formants and harmonics. This reduces the entropy of the signal, which is the difference between the coded signal and the quantization noise, thus lowering the bitrate.
+ Deemphasizing spectral valleys; by using different coefficients in the analysis and synthesis part of the prefilter and noise shaping quantizer, the levels of the spectral valleys can be decreased relative to the levels of the spectral peaks such as speech formants and harmonics. This reduces the entropy of the signal, which is the difference between the coded signal and the quantization noise, thus lowering the bitrate.Matching the levels of the decoded speech formants to the levels of the original speech formants; an adjustment gain and a first order tilt coefficient are computed to compensate for the effect of the noise shaping quantization on the level and spectral tilt.
@@ 3803,23 +4901,23 @@ fl=sum(f(i),iNoise shaping and spectral deemphasis illustration.
 shows an example of an input signal spectrum (1). After deemphasis and level matching, the spectrum has deeper valleys (2). The quantization noise spectrum (3) more or less follows the input signal spectrum, while having slightly less pronounced peaks. The entropy, which provides a lower bound on the bitrate for encoding the excitation signal, is proportional to the area between the deemphasized spectrum (2) and the quantization noise spectrum (3). Without deemphasis, the entropy is proportional to the area between input spectrum (1) and quantization noise (3)  clearly higher.
+ shows an example of an input signal spectrum (1). After deemphasis and level matching, the spectrum has deeper valleys (2). The quantization noise spectrum (3) more or less follows the input signal spectrum, while having slightly less pronounced peaks. The entropy, which provides a lower bound on the bitrate for encoding the excitation signal, is proportional to the area between the deemphasized spectrum (2) and the quantization noise spectrum (3). Without deemphasis, the entropy is proportional to the area between input spectrum (1) and quantization noise (3)  clearly higher.
 The transformation from input signal to deemphasized signal can be described as a filtering operation with a filter
+ The transformation from input signal to deemphasized signal can be described as a filtering operation with a filter
@@ 3828,11 +4926,11 @@ H(z) = G * ( 1  c_tilt * z^(1) ) * 
@@ 3844,33 +4942,37 @@ Wana(z) = (1  \ (a_ana(k) * z^(k))*(1  z^(L) \ b_ana(k)*z^(k)),
 All noise shaping parameters are computed and applied per subframe of 5 milliseconds. First, an LPC analysis is performed on a windowed signal block of 15 milliseconds. The signal block has a lookahead of 5 milliseconds relative to the current subframe, and the window is an asymmetric sine window. The LPC analysis is done with the autocorrelation method, with an order of 16 for best quality or 12 in low complexity operation. The quantization gain is found as the squareroot of the residual energy from the LPC analysis, multiplied by a value inversely proportional to the coding quality control parameter and the pitch correlation.
+ All noise shaping parameters are computed and applied per subframe of 5 ms. First, an LPC analysis is performed on a windowed signal block of 15 ms. The signal block has a lookahead of 5 ms relative to the current subframe, and the window is an asymmetric sine window. The LPC analysis is done with the autocorrelation method, with an order of 16 for best quality or 12 in low complexity operation. The quantization gain is found by taking the square root of the residual energy from the LPC analysis and multiplying it by a value inversely proportional to the coding quality control parameter and the pitch correlation.
 Next we find the two sets of shortterm noise shaping coefficients a_ana(k) and a_syn(k), by applying different amounts of bandwidth expansion to the coefficients found in the LPC analysis. This bandwidth expansion moves the roots of the LPC polynomial towards the origo, using the formulas
+ Next we find the two sets of shortterm noise shaping coefficients a_ana(k) and a_syn(k), by applying different amounts of bandwidth expansion to the coefficients found in the LPC analysis. This bandwidth expansion moves the roots of the LPC polynomial towards the origin, using the formulas
 where a(k) is the k'th LPC coefficient and the bandwidth expansion factors g_ana and g_syn are calculated as
+ where a(k) is the k'th LPC coefficient, and the bandwidth expansion factors g_ana and g_syn are calculated as
@@ 3884,6 +4986,7 @@ g_syn = 0.94 + 0.02*C,
@@ 3897,6 +5000,7 @@ b_syn = F_syn * [0.25, 0.5, 0.25].
@@ 3904,13 +5008,13 @@ c_tilt = 0.04 + 0.06 * C
for voiced frames, where C again is the coding quality control parameter and is between 0 and 1.
 The adjustment gain G serves to correct any level mismatch between original and decoded signal that might arise from the noise shaping and deemphasis. This gain is computed as the ratio of the prediction gain of the shortterm analysis and synthesis filter coefficients. The prediction gain of an LPC synthesis filter is the squareroot of the output energy when the filter is excited by a unitenergy impulse on the input. An efficient way to compute the prediction gain is by first computing the reflection coefficients from the LPC coefficients through the stepdown algorithm, and extracting the prediction gain from the reflection coefficients as
+ The adjustment gain G serves to correct any level mismatch between the original and decoded signals that might arise from the noise shaping and deemphasis. This gain is computed as the ratio of the prediction gain of the shortterm analysis and synthesis filter coefficients. The prediction gain of an LPC synthesis filter is the square root of the output energy when the filter is excited by a unitenergy impulse on the input. An efficient way to compute the prediction gain is by first computing the reflection coefficients from the LPC coefficients through the stepdown algorithm, and extracting the prediction gain from the reflection coefficients as
@@ 3925,35 +5029,35 @@ c_tilt = 0.04 + 0.06 * C
 In the prefilter the input signal is filtered using the spectral valley deemphasis filter coefficients from the noise shaping analysis, see . By applying only the noise shaping analysis filter to the input signal, it provides the input to the noise shaping quantizer.
+ In the prefilter the input signal is filtered using the spectral valley deemphasis filter coefficients from the noise shaping analysis (see ). By applying only the noise shaping analysis filter to the input signal, it provides the input to the noise shaping quantizer.
 The prediction analysis is performed in one of two ways depending on how the pitch estimator classified the frame. The processing for voiced and unvoiced speech are described in and , respectively. Inputs to this function include the prewhitened signal from the pitch estimator, see .
+ The prediction analysis is performed in one of two ways depending on how the pitch estimator classified the frame. The processing for voiced and unvoiced speech is described in and , respectively. Inputs to this function include the prewhitened signal from the pitch estimator (see ).
 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 fifthorder 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 modeling of the output signal. This LTP residual signal is the input to an LPC analysis where the LPCs are estimated using Burg's 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 back to LPC coefficients using the full procedure in . By using LPC coefficients derived from the quantized LSF 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 then used to filter the highpass filtered input signal and measure residual energy for each of the four subframes.
 For a speech signal that has been classified as unvoiced there is no need for LTP filtering as it has already been determined that the prewhitened input signal is not periodic enough within the allowed pitch period range for an LTP analysis to be worthwhile the cost in terms of complexity and rate. Therefore, the prewhitened input signal is discarded and instead the highpass filtered input signal is used for LPC analysis using Burgs method. The resulting LPC coefficients are converted to an LSF vector, quantized as described in the following section and transformed back to obtain quantized LPC coefficients. The quantized LPC coefficients are used to filter the highpass filtered input signal and measure a residual energy for each of the four subframes.
+ For a speech signal that has been classified as unvoiced, there is no need for LTP filtering, as it has already been determined that the prewhitened input signal is not periodic enough within the allowed pitch period range for LTP analysis to be worth the cost in terms of complexity and rate. The prewhitened input signal is therefore discarded, and instead the highpass filtered input signal is used for LPC analysis using Burg's method. The resulting LPC coefficients are converted to an LSF vector and quantized as described in the following section. They are then transformed back to obtain quantized LPC coefficients, which are then used to filter the highpass filtered input signal and measure residual energy for each of the four subframes.
 The purpose of quantization in general is to significantly lower the bit rate at the cost of some introduced distortion. A higher rate should always result in lower distortion, and lowering the rate will generally lead to higher distortion. A commonly used but generally suboptimal approach is to use a quantization method with a constant rate where only the error is minimized when quantizing.
+ In general, the purpose of quantization is to significantly lower the bitrate at the cost of introducing some distortion. A higher rate should always result in lower distortion, and lowering the rate will generally lead to higher distortion. A commonly used but generally suboptimal approach is to use a quantization method with a constant rate, where only the error is minimized when quantizing.
 Instead, we minimize an objective function that consists of a weighted sum of rate and distortion, and use a codebook with an associated nonuniform rate table. Thus, we take into account that the probability mass function for selecting the codebook entries are by no means guaranteed to be uniform in our scenario. The advantage of this approach is that it ensures that rarely used codebook vector centroids, which are modelling statistical outliers in the training set can be quantized with a low error but with a relatively high cost in terms of a high rate. At the same time this approach also provides the advantage that frequently used centroids are modelled with low error and a relatively low rate. This approach will lead to equal or lower distortion than the fixed rate codebook at any given average rate, provided that the data is similar to the data used for training the codebook.
+ Instead, we minimize an objective function that consists of a weighted sum of rate and distortion, and use a codebook with an associated nonuniform rate table. Thus, we take into account that the probability mass function for selecting the codebook entries is by no means guaranteed to be uniform in our scenario. This approach has several advantages. It ensures that rarely used codebook vector centroids, which are modeling statistical outliers in the training set, are quantized with low error at the expense of a high rate. At the same time, it allows modeling frequently used centroids with low error and a relatively low rate. This approach leads to equal or lower distortion than the fixedrate codebook at any given average rate, provided that the data is similar to that used for training the codebook.
 Instead of minimizing the error in the LSF domain, we map the errors to better approximate spectral distortion by applying an individual weight to each element in the error vector. The weight vectors are calculated for each input vector using the Inverse Harmonic Mean Weighting (IHMW) function proposed by Laroia et al., see .
+ Instead of minimizing the error in the LSF domain, we map the errors to better approximate spectral distortion by applying an individual weight to each element in the error vector. The weight vectors are calculated for each input vector using the Inverse Harmonic Mean Weighting (IHMW) function proposed by Laroia et al. (see ).
Consequently, we solve the following minimization problem, i.e.,
@@ 3968,7 +5072,7 @@ 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 .
+ We arrange the codebook in a multiplestage 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 ).
@@ 3991,7 +5095,7 @@ LSF ++ res_1 ++ res_{S1} ++
 By storing total of M codebook vectors, i.e.,
+ By storing a total of M codebook vectors, i.e.,
 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 is 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 to carry out a full search 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 their 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 real time, 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. Performance almost as good as that of the infeasible full search can be obtained at substantially lower complexity by using this approach (see, e.g., ).
 If the input is stable, finding the best candidate will usually result in the quantized vector also being stable, but due to the multistage approach it could in theory happen that the best quantization candidate is unstable and because of this there is a need to explicitly ensure that the quantized vectors are stable. Therefore we apply a LSF stabilization method which ensures that the LSF parameters are within valid range, increasingly sorted, and have minimum distances between each other and the border values that have been predetermined as the 0.01 percentile distance values from a large training set.
+ If the input is stable, finding the best candidate usually results in a quantized vector that is also stable. Due to the multistage approach, however, it is theoretically possible that the best quantization candidate is unstable. Because of this, it is necessary to explicitly ensure that the quantized vectors are stable. Therefore we apply an LSF stabilization method which ensures that the LSF parameters are within valid range, increasingly sorted, and have minimum distances between each other and the border values that have been predetermined as the 0.01 percentile distance values from a large training set.
@@ 4034,7 +5138,7 @@ T =   Ms
 For voiced frames, the prediction analysis described in resulted in four sets (one set per subframe) of five LTP coefficients, plus four weighting matrices. Also, the LTP coefficients for each subframe are quantized using entropy constrained vector quantization. A total of three vector codebooks are available for quantization, with different ratedistortion tradeoffs. The three codebooks have 10, 20 and 40 vectors and average rates of about 3, 4, and 5 bits per vector, respectively. Consequently, the first codebook has larger average quantization distortion at a lower rate, whereas the last codebook has smaller average quantization distortion at a higher rate. Given the weighting matrix W_ltp and LTP vector b, the weighted ratedistortion measure for a codebook vector cb_i with rate r_i is give by
+ For voiced frames, the prediction analysis described in resulted in four sets (one set per subframe) of five LTP coefficients, plus four weighting matrices. The LTP coefficients for each subframe are quantized using entropy constrained vector quantization. A total of three vector codebooks are available for quantization, with different ratedistortion tradeoffs. The three codebooks have 10, 20, and 40 vectors and average rates of about 3, 4, and 5 bits per vector, respectively. Consequently, the first codebook has larger average quantization distortion at a lower rate, whereas the last codebook has smaller average quantization distortion at a higher rate. Given the weighting matrix W_ltp and LTP vector b, the weighted ratedistortion measure for a codebook vector cb_i with rate r_i is give by
where u is a fixed, heuristicallydetermined parameter balancing the distortion and rate. Which codebook gives the best performance for a given LTP vector depends on the weighting matrix for that LTP vector. For example, for a low valued W_ltp, it is advantageous to use the codebook with 10 vectors as it has a lower average rate. For a large W_ltp, on the other hand, it is often better to use the codebook with 40 vectors, as it is more likely to contain the best codebook vector.
 The weighting matrix W_ltp depends mostly on two aspects of the input signal. The first is the periodicity of the signal; the more periodic the larger W_ltp. The second is the change in signal energy in the current subframe, relative to the signal one pitch lag earlier. A decaying energy leads to a larger W_ltp than an increasing energy. Both aspects do not fluctuate very fast which causes the W_ltp matrices for different subframes of one frame often to be similar. As a result, one of the three codebooks typically gives good performance for all subframes. Therefore the codebook search for the subframe LTP vectors is constrained to only allow codebook vectors to be chosen from the same codebook, resulting in a rate reduction.
+ The weighting matrix W_ltp depends mostly on two aspects of the input signal. The first is the periodicity of the signal; the more periodic, the larger W_ltp. The second is the change in signal energy in the current subframe, relative to the signal one pitch lag earlier. A decaying energy leads to a larger W_ltp than an increasing energy. Both aspects fluctuate relatively slowly, which causes the W_ltp matrices for different subframes of one frame often to be similar. Because of this, one of the three codebooks typically gives good performance for all subframes, and therefore the codebook search for the subframe LTP vectors is constrained to only allow codebook vectors to be chosen from the same codebook, resulting in a rate reduction.
 To find the best codebook, each of the three vector codebooks is used to quantize all subframe LTP vectors and produce a combined weighted ratedistortion measure for each vector codebook and the vector codebook with the lowest combined ratedistortion over all subframes is chosen. The quantized LTP vectors are used in the noise shaping quantizer, and the index of the codebook plus the four indices for the four subframe codebook vectors are passed on to the range encoder.
+ To find the best codebook, each of the three vector codebooks is used to quantize all subframe LTP vectors and produce a combined weighted ratedistortion measure for each vector codebook. The vector codebook with the lowest combined ratedistortion over all subframes is chosen. The quantized LTP vectors are used in the noise shaping quantizer, and the index of the codebook plus the four indices for the four subframe codebook vectors are passed on to the range encoder.
@@ 4064,7 +5168,7 @@ T =   Ms
 Range encoding is a well known method for entropy coding in which a bitstream sequence is continually updated with every new symbol, based on the probability for that symbol. It is similar to arithmetic coding but rather than being restricted to generating binary output symbols, it can generate symbols in any chosen number base. In SILK all side information is range encoded. Each quantized parameter has its own cumulative density function based on histograms for the quantization indices obtained by running a training database.
+ Range encoding is a well known method for entropy coding in which a bitstream sequence is continually updated with every new symbol, based on the probability for that symbol. It is similar to arithmetic coding, but rather than being restricted to generating binary output symbols, it can generate symbols in any chosen number base. In SILK all side information is range encoded. Each quantized parameter has its own cumulative density function based on histograms for the quantization indices obtained by running a training database.
@@ 4078,32 +5182,35 @@ T =   Ms
Copy from CELT draft.
+Most of the aspects of the CELT encoder can be directly derived from the description
+of the decoder. For example, the filters and rotations in the encoder are simply the
+inverse of the operation performed by the decoder. Similarly, the quantizers generally
+optimize for the mean square error (because noise shaping is part of the bitstream itself),
+so no special search is required. For this reason, only the less straightforward aspects of the
+encoder are described here.


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.
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 pitch prefilter is applied after the preemphasis and before the deemphasis. It's applied
+in such a way as to be the inverse of the decoder's postfilter. The main nonobvious aspect of the
+prefilter is the selection of the pitch period. The pitch search should be optimised for the
+following criteria:
+
+continuity: it is important that the pitch period
+does not change abruptly between frames; and
+avoidance of pitch multiples: when the period used is a multiple of the real period
+(lower frequency fundamental), the postfilter loses most of its ability to reduce noise
+
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
+bands for the smallest (2.5 ms) frame size. The larger frame sizes use integer
+multiples of the 2.5 ms layout. For each band, the encoder
computes the energy that will later be encoded. Each band is then normalized by the
square root of the nonquantized energy, such that each band now forms a unit vector X.
+square root of the unquantized energy, such that each band now forms a unit vector X.
The energy and the normalization are computed by compute_band_energies()
and normalise_bands() (bands.c), respectively.
@@ 4112,69 +5219,13 @@ and normalise_bands() (bands.c), respectively.
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,
as implemented in quant_bands.c



The coarse quantization of the energy uses a fixed resolution of 6 dB.
To minimize the bitrate, prediction is applied both in time (using the previous frame)
and in frequency (using the previous bands). The prediction using the
previous frame can be disabled, creating an "intra" frame where the energy
is coded without reference to prior frames. An encoder is able to choose the
mode used at will based on both loss robustness and efficiency
considerations.
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. Identical prediction
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
quant_coarse_energy() (quant_bands.c). The encoding of the Laplacedistributed values is
implemented in ec_laplace_encode() (laplace.c).







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
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).



If any bits are unused at the end of the encoding process, these bits are used to
increase the resolution of the fine energy encoding in some bands. Priority is given
to the bands for which the allocation () was rounded
down. At the same level of priority, lower bands are encoded first. Refinement bits
are added until there is no more room for fine energy or until each band
has gained an additional bit of precision or has the maximum fine
energy precision. This is implemented in quant_energy_finalise()
(quant_bands.c).
+Energy quantization (both coarse and fine) can be easily understood from the decoding process.
+The quantizer simply minimizes the log energy error for each band, with the exception that at
+very low rate, larger errors are allowed in the coarse energy to minimize the bitrate. When the
+avaialble CPU requirements allow it, it is best to try encoding the coarse energy both with and without
+interframe prediction such that the best prediction mode can be selected. The optimal mode depends on
+the coding rate, the available bitrate, and the current rate of packet loss.




@@ 4201,7 +5252,7 @@ L2 norm.
The search for the best codevector y is performed by alg_quant()
(vq.c). There are several possible approaches to the
search with a tradeoff between quality and complexity. The method used in the reference
+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
R = X  p' onto the codebook pyramid of K1 pulses:
@@ 4214,70 +5265,27 @@ 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:



J = R^T*y / y
+
+
+
The search described above is considered to be a good tradeoff between quality
and computational cost. However, there are other possible ways to search the PVQ
codebook and the implementors MAY use any other search methods.
+codebook and the implementers 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 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.







When encoding a stereo stream, some parameters are shared across the left and right channels, while others are transmitted separately for each channel, or jointly encoded. Only one copy of the flags for the features, transients and pitch (pitch
period and filter parameters) are transmitted. The coarse and fine energy parameters are transmitted separately for each channel. Both the coarse energy and fine energy (including the remaining fine bits at the end of the stream) have the left and right bands interleaved in the stream, with the left band encoded first.



The main difference between mono and stereo coding is the PVQ coding of the normalized vectors. In stereo mode, a normalized midside (MS) encoding is used. Let L and R be the normalized vector of a certain band for the left and right channels, respectively. The mid and side vectors are computed as M=L+R and S=LR and no longer have unit norm.



From M and S, an angular parameter theta=2/pi*atan2(S, M) is computed. The theta parameter is converted to a Q14 fixedpoint parameter itheta, which is quantized on a scale from 0 to 1 with an interval of 2^qb, where qb is
based the number of bits allocated to the band. From here on, the value of itheta MUST be treated in a bitexact manner since both the encoder and decoder rely on it to infer the bit allocation.


Let m=M/M and s=S/S; m and s are separately encoded with the PVQ encoder described in . The number of bits allocated to m and s depends on the value of itheta.




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.





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.


@@ 4306,10 +5314,10 @@ Compliance with this specification means that a decoder's output MUST be
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
+special applications for which a frame size different from 2.5, 5, 10, or 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
+only the CELT layer is available, which is available using the celt_* function
calls in celt.h.
@@ 4318,7 +5326,7 @@ calls in celt.h.
The codec needs to take appropriate security considerations
+Implementations of the Opus codec need to take appropriate security considerations
into account, as outlined in and .
It is extremely important for the decoder to be robust against malicious
payloads.
@@ 4326,7 +5334,7 @@ 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
+audio streams must not cause the encoder to misbehave because this would
allow an attacker to attack transcoding gateways.
@@ 4334,18 +5342,33 @@ The reference implementation contains no known buffer overflow or cases where
a specially crafted packet or audio segment could cause a significant increase
in CPU load.
However, on certain CPU architectures where denormalized floatingpoint
 operations are much slower than normal floatingpoint operations it is
 possible for some audio content (e.g., silence or nearsilence) to cause such
+ operations are much slower than normal floatingpoint operations, it is
+ possible for some audio content (e.g., silence or nearsilence) to cause a certain
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
+ on the target architecture, so it is difficult to guarantee that 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).

+For architectures on which denormals are problematic, it is RECOMMENDED to
+add very small floatingpoint offsets to the affected signals
+to prevent significant numbers of denormalized
+ operations. Alternatively, it is often possible to configure the hardware to treat
+ denormals as zero (DAZ).
No such issue exists for the fixedpoint reference implementation.
+The reference implementation was validated in the following conditions:
+
+Sending the decoder valid packets generated by the reference encoder and
+verifying that the decoder's final range coder state matches that of the encoder.
+Sending the decoder packets generated by the reference encoder, after random corruption.
+Sending the decoder random packets to the decoder.
+Altering the encoder to make random coding decisions (internal fuzzing), including
+mode switching and verifying that the range coder final states match.
+
+In all of the conditions above, both the encoder and the decoder were run inside
+the Valgrind memory debugger, which tracks reads and writes to invalid memory
+regions, as well as use of uninitialized memory. There were no error reported
+on any of the tested conditions.
+
@@ 4358,10 +5381,11 @@ 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. 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.
+Christopher Montgomery, and Karsten Vandborg Soerensen. We would also
+like to thank Igor Dyakonov and 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 feedback, as well as Ralph Giles, Christian Hoene, and
+Kat Walsh, for their feedback on the draft.
@@ 4582,6 +5606,179 @@ Development snapshots are provided at
+
+
+To use the internal framing described in , the decoder
+ must know the total length of the Opus packet, in bytes.
+This section describes a simple variation of that framing which can be used
+ when the total length of the packet is not known.
+Nothing in the encoding of the packet itself allows a decoder to distinguish
+ between the regular, undelimited framing and the selfdelimiting framing
+ described in this appendix.
+Which one is used and where must be established by context at the transport
+ layer.
+It is RECOMMENDED that a transport layer choose exactly one framing scheme,
+ rather than allowing an encoder to signal which one it wants to use.
+
+
+
+For example, although a regular Opus stream does not support more than two
+ channels, a multichannel Opus stream may be formed from several one and
+ twochannel streams.
+To pack an Opus packet from each of these streams together in a single packet
+ at the transport layer, one could use the selfdelimiting framing for all but
+ the last stream, and then the regular, undelimited framing for the last one.
+Reverting to the undelimited framing for the last stream saves overhead
+ (because the total size of the transportlayer packet will still be known),
+ and ensures that a "multichannel" stream which only has a single Opus stream
+ uses the same framing as a regular Opus stream does.
+This avoids the need for signaling to distinguish these two cases.
+
+
+
+The selfdelimiting framing is identical to the regular, undelimited framing
+ from , except that each Opus packet contains one extra
+ length field, encoded using the same one or twobyte scheme from
+ .
+This extra length immediately precedes the compressed data of the first Opus
+ frame in the packet, and is interpreted in the various modes as follows:
+
+
+Code 0 packets: It is the length of the single Opus frame (see
+ ).
+
+
+Code 1 packets: It is the length used for both of the Opus frames (see
+ ).
+
+
+Code 2 packets: It is the length of the second Opus frame (see
+ ).
+
+CBR Code 3 packets: It is the length used for all of the Opus frames (see
+ ).
+
+VBR Code 3 packets: It is the length of the last Opus frame (see
+ ).
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+