+ original value of ftb was not greater than 8, then t is decoded with

+ t = ec_decode(ft), and the decoder state is updated with the

+ three-tuple (t,t+1,ft).

</t>

</section>

-<section anchor="encoder-tell" title="Current Bit Usage">

+<section anchor="decoder-tell" title="Current Bit Usage">

<t>

- The bit allocation routines in Opus need to be able to determine a

+ The bit allocation routines in CELT need to be able to determine a

conservative upper bound on the number of bits that have been used

- to encode the current frame thus far. This drives allocation

- decisions and ensures that the range code will not overflow the

- output buffer. This is computed in the reference implementation to

- fractional bit precision by the function ec_enc_tell()

- (rangeenc.c).

- Like all operations in the range encoder, it must

- be implemented in a bit-exact manner.

+ to decode from the current frame thus far. This drives allocation

+ decisions which must match those made in the encoder. This is

+ computed in the reference implementation to fractional bit precision

+ by the function ec_dec_tell() (rangedec.c). Like all

+ operations in the range decoder, it must be implemented in a

+ bit-exact manner, and must produce exactly the same value returned by

+ ec_enc_tell() after encoding the same symbols.

</t>

</section>

</section>

- <section title='SILK Encoder'>

+ <section anchor='outline_decoder' title='SILK Decoder'>

+ <t>

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

+ </t>

+ <section title="Decoder Modules">

<t>

- In the following, we focus on the core encoder and describe its components. For simplicity, we will refer to the core encoder simply as the encoder in the remainder of this document. An overview of the encoder is given in <xref target="encoder_figure" />.

+ An overview of the decoder is given in <xref target="decoder_figure" />.

+ <figure align="center" anchor="decoder_figure">

+ <artwork align="center">

+ <![CDATA[

+

+ +---------+ +------------+

+-->| Range |--->| Decode |---------------------------+

+ 1 | Decoder | 2 | Parameters |----------+ 5 |

+ +---------+ +------------+ 4 | |

+ 3 | | |

+ \/ \/ \/

+ +------------+ +------------+ +------------+

+ | Generate |-->| LTP |-->| LPC |-->

+ | Excitation | | Synthesis | | Synthesis | 6

+ +------------+ +------------+ +------------+

+

+1: Range encoded bitstream

+2: Coded parameters

+3: Pulses and gains

+4: Pitch lags and LTP coefficients

+5: LPC coefficients

+6: Decoded signal

+]]>

+ </artwork>

+ <postamble>Decoder block diagram.</postamble>

+ </figure>

</t>

- <figure align="center" anchor="encoder_figure">

- <artwork align="center">

- <![CDATA[

- +---+

- +----------------------------->| |

- +---------+ | +---------+ | |

- |Voice | | |LTP | | |

- +----->|Activity |-----+ +---->|Scaling |---------+--->| |

- | |Detector | 3 | | |Control |<+ 12 | | |

- | +---------+ | | +---------+ | | | |

- | | | +---------+ | | | |

- | | | |Gains | | 11 | | |

- | | | +->|Processor|-|---+---|--->| R |

- | | | | | | | | | | a |

- | \/ | | +---------+ | | | | n |

- | +---------+ | | +---------+ | | | | g |

- | |Pitch | | | |LSF | | | | | e |

- | +->|Analysis |-+ | |Quantizer|-|---|---|--->| |

- | | | |4| | | | | 8 | | | E |->

- | | +---------+ | | +---------+ | | | | n |14

- | | | | 9/\ 10| | | | | c |

- | | | | | \/ | | | | o |

- | | +---------+ | | +----------+| | | | d |

- | | |Noise | +--|->|Prediction|+---|---|--->| e |

- | +->|Shaping |-|--+ |Analysis || 7 | | | r |

- | | |Analysis |5| | | || | | | |

- | | +---------+ | | +----------+| | | | |

- | | | | /\ | | | | |

- | | +---------|--|-------+ | | | | |

- | | | \/ \/ \/ \/ \/ | |

- | +---------+ | | +---------+ +------------+ | |

- | |High-Pass| | | | | |Noise | | |

--+->|Filter |-+----+----->|Prefilter|------>|Shaping |->| |

-1 | | 2 | | 6 |Quantization|13| |

- +---------+ +---------+ +------------+ +---+

-

-1: Input speech signal

-2: High passed input signal

-3: Voice activity estimate

-4: Pitch lags (per 5 ms) and voicing decision (per 20 ms)

-5: Noise shaping quantization coefficients

- - Short term synthesis and analysis

- noise shaping coefficients (per 5 ms)

- - Long term synthesis and analysis noise

- shaping coefficients (per 5 ms and for voiced speech only)

- - Noise shaping tilt (per 5 ms)

- - Quantizer gain/step size (per 5 ms)

-6: Input signal filtered with analysis noise shaping filters

-7: Short and long term prediction coefficients

- LTP (per 5 ms) and LPC (per 20 ms)

-8: LSF quantization indices

-9: LSF coefficients

-10: Quantized LSF coefficients

-11: Processed gains, and synthesis noise shape coefficients

-12: LTP state scaling coefficient. Controlling error propagation

- / prediction gain trade-off

-13: Quantized signal

-14: Range encoded bitstream

-

-]]>

- </artwork>

- <postamble>Encoder block diagram.</postamble>

- </figure>

-

- <section title='Voice Activity Detection'>

+ <section title='Range Decoder'>

<t>

- The input signal is processed by a VAD (Voice Activity Detector) to produce a measure of voice activity, and also spectral tilt and signal-to-noise estimates, for each frame. The VAD uses a sequence of half-band 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 high-pass filtered with a first-order MA (Moving Average) filter (with transfer function H(z) = 1-z^(-1)) to reduce the energy at the lowest frequencies. For each frame, the signal energy per subband is computed. In each subband, a noise level estimator tracks the background noise level and an SNR (Signal-to-Noise 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:

- <list style="symbols">

- <t>

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

- </t>

-

- <t>

- Smoothed subband SNRs. Temporally smoothed subband SNR values.

- </t>

-

- <t>

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

- </t>

-

- <t>

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

- </t>

- </list>

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

</t>

</section>

- <section title='High-Pass Filter'>

+ <section title='Decode Parameters'>

<t>

- The input signal is filtered by a high-pass filter to remove the lowest part of the spectrum that contains little speech energy and may contain background noise. This is a second order ARMA (Auto Regressive Moving Average) filter with a cut-off frequency around 70 Hz.

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

</t>

+

<t>

- In the future, a music detector may also be used to lower the cut-off frequency when the input signal is detected to be music rather than speech.

+ When a voiced frame is decoded and LTP codebook selection and indices are received, LTP coefficients are decoded using the selected codebook by choosing the vector that corresponds to the given codebook index in that codebook. This is done for each of the four subframes.

+ The LPC coefficients are decoded from the LSF codebook by first adding the chosen vectors, one vector from each stage of the codebook. The resulting LSF vector is stabilized using the same method that was used in the encoder, see

+ <xref target='lsf_stabilizer_overview_section' />. The LSF coefficients are then converted to LPC coefficients, and passed on to the LPC synthesis filter.

- The high-passed input signal is processed by the open loop pitch estimator shown in <xref target='pitch_estimator_figure' />.

- <figure align="center" anchor="pitch_estimator_figure">

- <artwork align="center">

- <![CDATA[

- +--------+ +----------+

- |2 x Down| |Time- |

- +->|sampling|->|Correlator| |

- | | | | | |4

- | +--------+ +----------+ \/

- | | 2 +-------+

- | | +-->|Speech |5

- +---------+ +--------+ | \/ | |Type |->

- |LPC | |Down | | +----------+ | |

- +->|Analysis | +->|sample |-+------------->|Time- | +-------+

- | | | | |to 8 kHz| |Correlator|----------->

- | +---------+ | +--------+ |__________| 6

- | | | |3

- | \/ | \/

- | +---------+ | +----------+

- | |Whitening| | |Time- |

--+->|Filter |-+--------------------------->|Correlator|----------->

-1 | | | | 7

- +---------+ +----------+

-

-1: Input signal

-2: Lag candidates from stage 1

-3: Lag candidates from stage 2

-4: Correlation threshold

-5: Voiced/unvoiced flag

-6: Pitch correlation

-7: Pitch lags

-]]>

- </artwork>

- <postamble>Block diagram of the pitch estimator.</postamble>

- </figure>

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

- <list style="symbols">

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

-

- <t>

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

- <list style="symbols">

- <t>

- Whether the previous frame was classified as voiced

- </t>

- <t>

- The speech activity level

- </t>

- <t>

- The spectral tilt.

- </t>

- </list>

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

- </t>

- <t>

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

- </t>

- </list>

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

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

- <list style="symbols">

- <t>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.</t>

- <t>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.</t>

- <t>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.</t>

- <t>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.</t>

+ 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

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

- </t>

+ using the pitch lag L, and the decoded LTP coefficients b_i.

- <t>

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

- <figure align="center">

- <artwork align="center">

- <![CDATA[

- Wana(z)

-H(z) = G * ( 1 - c_tilt * z^(-1) ) * -------

- Wsyn(z),

- ]]>

- </artwork>

- </figure>

- having an adjustment gain G, a first order tilt adjustment filter with

- tilt coefficient c_tilt, and where

- <figure align="center">

- <artwork align="center">

- <![CDATA[

- 16 d

- __ __

-Wana(z) = (1 - \ (a_ana(k) * z^(-k))*(1 - z^(-L) \ b_ana(k)*z^(-k)),

- /_ /_

- k=1 k=-d

- ]]>

- </artwork>

- </figure>

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

+ For unvoiced speech, the output signal is simply a copy of the excitation signal, i.e., e_LPC(n) = e(n).

</t>

+ </section>

+ <section title='LPC Synthesis'>

<t>

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

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

<figure align="center">

<artwork align="center">

<![CDATA[

- 16 d

- __ __

-Wsyn(z) = (1 - \ (a_syn(k) * z^(-k))*(1 - z^(-L) \ b_syn(k)*z^(-k)).

- /_ /_

- k=1 k=-d

-]]>

+ d_LPC

+ __

+y(n) = e_LPC(n) + \ e_LPC(n - i) * a_i,

+ /_

+ i=1

+]]>

</artwork>

</figure>

- </t>

- <t>

- 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 look-ahead 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 square-root of the residual energy from the LPC analysis, multiplied by a value inversely proportional to the coding quality control parameter and the pitch correlation.

- </t>

- <t>

- Next we find the two sets of short-term 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

- <figure align="center">

- <artwork align="center">

- <![CDATA[

- a_ana(k) = a(k)*g_ana^k, and

- a_syn(k) = a(k)*g_syn^k,

- ]]>

- </artwork>

- </figure>

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

- <figure align="center">

- <artwork align="center">

- <![CDATA[

-g_ana = 0.94 - 0.02*C, and

-g_syn = 0.94 + 0.02*C,

- ]]>

- </artwork>

- </figure>

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

- </t>

-

- <t>

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

- <figure align="center">

- <artwork align="center">

- <![CDATA[

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

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

- ]]>

- </artwork>

- </figure>

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

- </t>

-

- <t>

- The tilt coefficient c_tilt is for unvoiced frames chosen as

- <figure align="center">

- <artwork align="center">

- <![CDATA[

-c_tilt = 0.4, and as

-c_tilt = 0.04 + 0.06 * C

- ]]>

- </artwork>

- </figure>

- for voiced frames, where C again is the coding quality control parameter and is between 0 and 1.

- </t>

- <t>

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

- <figure align="center">

- <artwork align="center">

- <![CDATA[

- K

- ___

- predGain = ( | | 1 - (r_k)^2 )^(-0.5),

- k=1

- ]]>

- </artwork>

- </figure>

- where r_k is the k'th reflection coefficient.

- </t>

-

- <t>

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

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

</t>

</section>

+ </section>

+ </section>

- <section title='Prefilter'>

- <t>

- In the prefilter the input signal is filtered using the spectral valley de-emphasis filter coefficients from the noise shaping analysis, see <xref target='noise_shaping_analysis_overview_section' />. 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 <xref target='pred_ana_voiced_overview_section' /> and <xref target='pred_ana_unvoiced_overview_section' />, respectively. Inputs to this function include the pre-whitened signal from the pitch estimator, see <xref target='pitch_estimator_overview_section' />.

- For a frame of voiced speech the pitch pulses will remain dominant in the pre-whitened input signal. Further whitening is desirable as it leads to higher quality at the same available bit-rate. To achieve this, a Long-Term Prediction (LTP) analysis is carried out to estimate the coefficients of a fifth order LTP filter for each of four sub-frames. 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 <xref target='lsf_quantizer_overview_section' />. 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 <xref target='ltp_quantizer_overview_section' />. The quantized LPC and LTP coefficients are now used to filter the high-pass 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 pre-whitened input signal is not periodic enough within the allowed pitch period range for an LTP analysis to be worth-while the cost in terms of complexity and rate. Therefore, the pre-whitened input signal is discarded and instead the high-pass 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 high-pass filtered input signal and measure a residual energy for each of the four subframes.

- <t>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 sub-optimal approach is to use a quantization method with a constant rate where only the error is minimized when quantizing.</t>

- <section title='Rate-Distortion Optimization'>

- <t>Instead, we minimize an objective function that consists of a weighted sum of rate and distortion, and use a codebook with an associated non-uniform 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.</t>

- 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 <xref target="laroia-icassp" />.

- Consequently, we solve the following minimization problem, i.e.,

- <figure align="center">

- <artwork align="center">

- <![CDATA[

-LSF_q = argmin { (LSF - c)' * W * (LSF - c) + mu * rate },

- c in C

- ]]>

- </artwork>

- </figure>

- where LSF_q is the quantized vector, LSF is the input vector to be quantized, and c is the quantized LSF vector candidate taken from the set C of all possible outcomes of the codebook.

- </t>

- </section>

- <section title='Multi-Stage Vector Codebook'>

- <t>

- 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. <xref target="sinervo-norsig" />. 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 <xref target='lsf_quantizer_structure_overview_figure' />.

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

- </t>

- </section>

- <section title='Survivor Based Codebook Search'>

- <t>

- 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 bit-rate 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 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. 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. <xref target='leblanc-tsap' />.

- <t>If the input is stable, finding the best candidate will usually result in the quantized vector also being stable, but due to the multi-stage 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 pre-determined as the 0.01 percentile distance values from a large training set.</t>

- </section>

- <section title='Off-Line Codebook Training'>

- <t>

- The vectors and rate tables for the multi-stage codebook have been trained by minimizing the average of the objective function for LSF vectors from a large training set.

- For voiced frames, the prediction analysis described in <xref target='pred_ana_voiced_overview_section' /> 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 rate-distortion trade-offs. The three codebooks have 10, 20 and 40 vectors and average rates of about 3, 4, and 5 bits per vector, respectively. Consequently, the first codebook has larger average quantization distortion at a lower rate, whereas the last codebook has smaller average quantization distortion at a higher rate. Given the weighting matrix W_ltp and LTP vector b, the weighted rate-distortion measure for a codebook vector cb_i with rate r_i is give by

- <figure align="center">

- <artwork align="center">

- <![CDATA[

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

-]]>

- </artwork>

- </figure>

- where u is a fixed, heuristically-determined parameter balancing the distortion and rate. Which codebook gives the best performance for a given LTP vector depends on the weighting matrix for that LTP vector. For example, for a low valued W_ltp, it is advantageous to use the codebook with 10 vectors as it has a lower average rate. For a large W_ltp, on the other hand, it is often better to use the codebook with 40 vectors, as it is more likely to contain the best codebook vector.

- The weighting matrix W_ltp depends mostly on two aspects of the input signal. The first is the periodicity of the signal; the more periodic the larger W_ltp. The second is the change in signal energy in the current subframe, relative to the signal one pitch lag earlier. A decaying energy leads to a larger W_ltp than an increasing energy. Both aspects 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.

- </t>

+<section anchor="energy-decoding" title="Energy Envelope Decoding">

+<t>

+The energy of each band is extracted from the bit-stream in two steps according

+to the same coarse-fine strategy used in the encoder. First, the coarse energy is

+decoded in unquant_coarse_energy() (quant_bands.c)

+based on the probability of the Laplace model used by the encoder.

+</t>

- <t>

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

- </t>

- </section>

+<t>

+After the coarse energy is decoded, the same allocation function as used in the

+encoder is called. This determines the number of

+bits to decode for the fine energy quantization. The decoding of the fine energy bits

+is performed by unquant_fine_energy() (quant_bands.c).

+Finally, like the encoder, the remaining bits in the stream (that would otherwise go unused)

+are decoded using unquant_energy_finalise() (quant_bands.c).

+</t>

+</section>

+</section>

- <section title='Noise Shaping Quantizer'>

- <t>

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

- </t>

- <t>

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

- </t>

+<section anchor="allocation" title="Bit allocation">

+<t>

+</t>

+</section>

- </section>

+<section anchor="PVQ-decoder" title="Spherical VQ Decoder">

+<t>

+In order to correctly decode the PVQ codewords, the decoder must perform exactly the same

+bits to pulses conversion as the encoder.

+</t>

- <section title='Range Encoder'>

- <t>

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

- </t>

+<section anchor="cwrs-decoder" title="Index Decoding">

+<t>

+The decoding of the codeword from the index is performed as specified in

+The index of the PVQ entry is obtained from the range coder and converted to

+a pulse vector by decode_pulses() (cwrs.c).

+</t>

+<t>The decoded normalized vector for each band is equal to</t>

+<t>X' = y/||y||,</t>

-<section title="CELT Encoder">

<t>

-Copy from CELT draft.

+This operation is implemented in mix_pitch_and_residual() (vq.c),

+which is the same function as used in the encoder.

</t>

+</section>

-<section anchor="forward-mdct" title="Forward MDCT">

-<t>The MDCT implementation has no special characteristics. The

-input is a windowed signal (after pre-emphasis) of 2*N samples and the output is N

-frequency-domain samples. A <spanx style="emph">low-overlap</spanx> 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 low-overlap window is created by zero-padding the basic window and inserting ones in the middle, such that the resulting window still satisfies power complementarity. The MDCT is computed in mdct_forward() (mdct.c), which includes the windowing operation and a scaling of 2/N.

-</t>

</section>

-<section anchor="normalization" title="Bands and Normalization">

+<section anchor="denormalization" title="Denormalization">

<t>

-The MDCT output is divided into bands that are designed to match the ear's critical

-bands for the smallest (2.5ms) frame size. The larger frame sizes use integer

-multiplies of the 2.5ms layout. For each band, the encoder

-computes the energy that will later be encoded. Each band is then normalized by the

-square root of the <spanx style="strong">non-quantized</spanx> 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.

+Just like each band was normalized in the encoder, the last step of the decoder before

+the inverse MDCT is to denormalize the bands. Each decoded normalized band is

+multiplied by the square root of the decoded energy. This is done by denormalise_bands()

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

+ Functions ec_enc_uint() or ec_enc_bits() are based on ec_encode() and

+ encode one of N equiprobable symbols, each with a frequency of 1,

+ where N may be as large as 2^32-1. Because ec_encode() is limited to

+ a total frequency of 2^16-1, this is done by encoding a series of

+ symbols in smaller contexts.

</t>

-

<t>

-The main difference between mono and stereo coding is the PVQ coding of the normalized vectors. In stereo mode, a normalized mid-side (M-S) 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=L-R and no longer have unit norm.

+ ec_enc_bits() (entenc.c) is defined, like

+ ec_encode_bin(), to take a two-tuple (fl,ftb), with <![CDATA[0 <= fl < 2^ftb

+ and ftb < 32. While ftb is greater than 8, it encodes bits (ftb-8) to

-From M and S, an angular parameter theta=2/pi*atan2(||S||, ||M||) is computed. The theta parameter is converted to a Q14 fixed-point 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 bit-exact manner since both the encoder and decoder rely on it to infer the bit allocation.

+ After all symbols are encoded, the stream must be finalized by

+ outputting a value inside the current range. Let end be the integer

+ in the interval [low,low+rng) with the largest number of trailing

+ zero bits. Then while end is not zero, the top 9 bits of end, e.g.,

+ <![CDATA[(end>>23), are sent to the carry buffer, and end is replaced by

+ After the carry buffer is finished outputting octets, the rest of the

+ output buffer is padded with zero octets. Finally, rem is set to the

+ special value -1. This process is implemented by ec_enc_done()

+ (rangeenc.c).

</t>

+</section>

+

+<section anchor="encoder-tell" title="Current Bit Usage">

<t>

-Let m=M/||M|| and s=S/||S||; m and s are separately encoded with the PVQ encoder described in <xref target="pvq"></xref>. The number of bits allocated to m and s depends on the value of itheta.

+ The bit allocation routines in Opus need to be able to determine a

+ conservative upper bound on the number of bits that have been used

+ to encode the current frame thus far. This drives allocation

+ decisions and ensures that the range code will not overflow the

+ output buffer. This is computed in the reference implementation to

+ fractional bit precision by the function ec_enc_tell()

+ (rangeenc.c).

+ Like all operations in the range encoder, it must

+ be implemented in a bit-exact manner.

+</t>

+</section>

+

+</section>

+

+ <section title='SILK Encoder'>

+ <t>

+ In the following, we focus on the core encoder and describe its components. For simplicity, we will refer to the core encoder simply as the encoder in the remainder of this document. An overview of the encoder is given in <xref target="encoder_figure" />.

+ </t>

+

+ <figure align="center" anchor="encoder_figure">

+ <artwork align="center">

+ <![CDATA[

+ +---+

+ +----------------------------->| |

+ +---------+ | +---------+ | |

+ |Voice | | |LTP | | |

+ +----->|Activity |-----+ +---->|Scaling |---------+--->| |

+ | |Detector | 3 | | |Control |<+ 12 | | |

+ | +---------+ | | +---------+ | | | |

+ | | | +---------+ | | | |

+ | | | |Gains | | 11 | | |

+ | | | +->|Processor|-|---+---|--->| R |

+ | | | | | | | | | | a |

+ | \/ | | +---------+ | | | | n |

+ | +---------+ | | +---------+ | | | | g |

+ | |Pitch | | | |LSF | | | | | e |

+ | +->|Analysis |-+ | |Quantizer|-|---|---|--->| |

+ | | | |4| | | | | 8 | | | E |->

+ | | +---------+ | | +---------+ | | | | n |14

+ | | | | 9/\ 10| | | | | c |

+ | | | | | \/ | | | | o |

+ | | +---------+ | | +----------+| | | | d |

+ | | |Noise | +--|->|Prediction|+---|---|--->| e |

+ | +->|Shaping |-|--+ |Analysis || 7 | | | r |

+ | | |Analysis |5| | | || | | | |

+ | | +---------+ | | +----------+| | | | |

+ | | | | /\ | | | | |

+ | | +---------|--|-------+ | | | | |

+ | | | \/ \/ \/ \/ \/ | |

+ | +---------+ | | +---------+ +------------+ | |

+ | |High-Pass| | | | | |Noise | | |

+-+->|Filter |-+----+----->|Prefilter|------>|Shaping |->| |

+1 | | 2 | | 6 |Quantization|13| |

+ +---------+ +---------+ +------------+ +---+

+

+1: Input speech signal

+2: High passed input signal

+3: Voice activity estimate

+4: Pitch lags (per 5 ms) and voicing decision (per 20 ms)

+5: Noise shaping quantization coefficients

+ - Short term synthesis and analysis

+ noise shaping coefficients (per 5 ms)

+ - Long term synthesis and analysis noise

+ shaping coefficients (per 5 ms and for voiced speech only)

+ - Noise shaping tilt (per 5 ms)

+ - Quantizer gain/step size (per 5 ms)

+6: Input signal filtered with analysis noise shaping filters

+7: Short and long term prediction coefficients

+ LTP (per 5 ms) and LPC (per 20 ms)

+8: LSF quantization indices

+9: LSF coefficients

+10: Quantized LSF coefficients

+11: Processed gains, and synthesis noise shape coefficients

+12: LTP state scaling coefficient. Controlling error propagation

+ / prediction gain trade-off

+13: Quantized signal

+14: Range encoded bitstream

+

+]]>

+ </artwork>

+ <postamble>Encoder block diagram.</postamble>

+ </figure>

+

+ <section title='Voice Activity Detection'>

+ <t>

+ The input signal is processed by a VAD (Voice Activity Detector) to produce a measure of voice activity, and also spectral tilt and signal-to-noise estimates, for each frame. The VAD uses a sequence of half-band 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 high-pass filtered with a first-order MA (Moving Average) filter (with transfer function H(z) = 1-z^(-1)) to reduce the energy at the lowest frequencies. For each frame, the signal energy per subband is computed. In each subband, a noise level estimator tracks the background noise level and an SNR (Signal-to-Noise 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:

+ <list style="symbols">

+ <t>

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

+ </t>

+

+ <t>

+ Smoothed subband SNRs. Temporally smoothed subband SNR values.

+ </t>

+

+ <t>

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

+ </t>

+

+ <t>

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

+ </t>

+ </list>

+ </t>

+ </section>

+

+ <section title='High-Pass Filter'>

+ <t>

+ The input signal is filtered by a high-pass filter to remove the lowest part of the spectrum that contains little speech energy and may contain background noise. This is a second order ARMA (Auto Regressive Moving Average) filter with a cut-off frequency around 70 Hz.

+ </t>

+ <t>

+ In the future, a music detector may also be used to lower the cut-off frequency when the input signal is detected to be music rather than speech.

+ The high-passed input signal is processed by the open loop pitch estimator shown in <xref target='pitch_estimator_figure' />.

+ <figure align="center" anchor="pitch_estimator_figure">

+ <artwork align="center">

+ <![CDATA[

+ +--------+ +----------+

+ |2 x Down| |Time- |

+ +->|sampling|->|Correlator| |

+ | | | | | |4

+ | +--------+ +----------+ \/

+ | | 2 +-------+

+ | | +-->|Speech |5

+ +---------+ +--------+ | \/ | |Type |->

+ |LPC | |Down | | +----------+ | |

+ +->|Analysis | +->|sample |-+------------->|Time- | +-------+

+ | | | | |to 8 kHz| |Correlator|----------->

+ | +---------+ | +--------+ |__________| 6

+ | | | |3

+ | \/ | \/

+ | +---------+ | +----------+

+ | |Whitening| | |Time- |

+-+->|Filter |-+--------------------------->|Correlator|----------->

+1 | | | | 7

+ +---------+ +----------+

+

+1: Input signal

+2: Lag candidates from stage 1

+3: Lag candidates from stage 2

+4: Correlation threshold

+5: Voiced/unvoiced flag

+6: Pitch correlation

+7: Pitch lags

+]]>

+ </artwork>

+ <postamble>Block diagram of the pitch estimator.</postamble>

+ </figure>

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

+ <list style="symbols">

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

+

+ <t>

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

+ <list style="symbols">

+ <t>

+ Whether the previous frame was classified as voiced

+ </t>

+ <t>

+ The speech activity level

+ </t>

+ <t>

+ The spectral tilt.

+ </t>

+ </list>

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

+ </t>

+ <t>

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

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

+ <list style="symbols">

+ <t>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.</t>

+ <t>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.</t>

+ <t>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.</t>

+ <t>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.</t>

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

+ </t>

+

+ <t>

+ The transformation from input signal to deemphasized signal can be described as a filtering operation with a filter

+ <figure align="center">

+ <artwork align="center">

+ <![CDATA[

+ Wana(z)

+H(z) = G * ( 1 - c_tilt * z^(-1) ) * -------

+ Wsyn(z),

+ ]]>

+ </artwork>

+ </figure>

+ having an adjustment gain G, a first order tilt adjustment filter with

+ tilt coefficient c_tilt, and where

+ <figure align="center">

+ <artwork align="center">

+ <![CDATA[

+ 16 d

+ __ __

+Wana(z) = (1 - \ (a_ana(k) * z^(-k))*(1 - z^(-L) \ b_ana(k)*z^(-k)),

+ /_ /_

+ k=1 k=-d

+ ]]>

+ </artwork>

+ </figure>

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

+ </t>

+

+ <t>

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

+ <figure align="center">

+ <artwork align="center">

+ <![CDATA[

+ 16 d

+ __ __

+Wsyn(z) = (1 - \ (a_syn(k) * z^(-k))*(1 - z^(-L) \ b_syn(k)*z^(-k)).

+ /_ /_

+ k=1 k=-d

+ ]]>

+ </artwork>

+ </figure>

+ </t>

+ <t>

+ 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 look-ahead 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 square-root of the residual energy from the LPC analysis, multiplied by a value inversely proportional to the coding quality control parameter and the pitch correlation.

+ </t>

+ <t>

+ Next we find the two sets of short-term 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

+ <figure align="center">

+ <artwork align="center">

+ <![CDATA[

+ a_ana(k) = a(k)*g_ana^k, and

+ a_syn(k) = a(k)*g_syn^k,

+ ]]>

+ </artwork>

+ </figure>

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

+ <figure align="center">

+ <artwork align="center">

+ <![CDATA[

+g_ana = 0.94 - 0.02*C, and

+g_syn = 0.94 + 0.02*C,

+ ]]>

+ </artwork>

+ </figure>

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

+ </t>

+

+ <t>

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

+ <figure align="center">

+ <artwork align="center">

+ <![CDATA[

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

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

+ ]]>

+ </artwork>

+ </figure>

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

+ </t>

+

+ <t>

+ The tilt coefficient c_tilt is for unvoiced frames chosen as

+ <figure align="center">

+ <artwork align="center">

+ <![CDATA[

+c_tilt = 0.4, and as

+c_tilt = 0.04 + 0.06 * C

+ ]]>

+ </artwork>

+ </figure>

+ for voiced frames, where C again is the coding quality control parameter and is between 0 and 1.

+ </t>

+ <t>

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

+ <figure align="center">

+ <artwork align="center">

+ <![CDATA[

+ K

+ ___

+ predGain = ( | | 1 - (r_k)^2 )^(-0.5),

+ k=1

+ ]]>

+ </artwork>

+ </figure>

+ where r_k is the k'th reflection coefficient.

+ </t>

+

+ <t>

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

+ </t>

+ </section>

+

+ <section title='Prefilter'>

+ <t>

+ In the prefilter the input signal is filtered using the spectral valley de-emphasis filter coefficients from the noise shaping analysis, see <xref target='noise_shaping_analysis_overview_section' />. 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 <xref target='pred_ana_voiced_overview_section' /> and <xref target='pred_ana_unvoiced_overview_section' />, respectively. Inputs to this function include the pre-whitened signal from the pitch estimator, see <xref target='pitch_estimator_overview_section' />.

+ For a frame of voiced speech the pitch pulses will remain dominant in the pre-whitened input signal. Further whitening is desirable as it leads to higher quality at the same available bit-rate. To achieve this, a Long-Term Prediction (LTP) analysis is carried out to estimate the coefficients of a fifth order LTP filter for each of four sub-frames. 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 <xref target='lsf_quantizer_overview_section' />. 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 <xref target='ltp_quantizer_overview_section' />. The quantized LPC and LTP coefficients are now used to filter the high-pass 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 pre-whitened input signal is not periodic enough within the allowed pitch period range for an LTP analysis to be worth-while the cost in terms of complexity and rate. Therefore, the pre-whitened input signal is discarded and instead the high-pass 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 high-pass filtered input signal and measure a residual energy for each of the four subframes.

+ <t>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 sub-optimal approach is to use a quantization method with a constant rate where only the error is minimized when quantizing.</t>

+ <section title='Rate-Distortion Optimization'>

+ <t>Instead, we minimize an objective function that consists of a weighted sum of rate and distortion, and use a codebook with an associated non-uniform 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.</t>

+ 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 <xref target="laroia-icassp" />.

+ Consequently, we solve the following minimization problem, i.e.,

+ <figure align="center">

+ <artwork align="center">

+ <![CDATA[

+LSF_q = argmin { (LSF - c)' * W * (LSF - c) + mu * rate },

+ c in C

+ ]]>

+ </artwork>

+ </figure>

+ where LSF_q is the quantized vector, LSF is the input vector to be quantized, and c is the quantized LSF vector candidate taken from the set C of all possible outcomes of the codebook.

+ </t>

+ </section>

+ <section title='Multi-Stage Vector Codebook'>

+ <t>

+ 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. <xref target="sinervo-norsig" />. 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 <xref target='lsf_quantizer_structure_overview_figure' />.

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

+ </t>

+ </section>

+ <section title='Survivor Based Codebook Search'>

+ <t>

+ 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 bit-rate 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 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. 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. <xref target='leblanc-tsap' />.

+ <t>If the input is stable, finding the best candidate will usually result in the quantized vector also being stable, but due to the multi-stage 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 pre-determined as the 0.01 percentile distance values from a large training set.</t>

+ </section>

+ <section title='Off-Line Codebook Training'>

+ <t>

+ The vectors and rate tables for the multi-stage codebook have been trained by minimizing the average of the objective function for LSF vectors from a large training set.

+ For voiced frames, the prediction analysis described in <xref target='pred_ana_voiced_overview_section' /> 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 rate-distortion trade-offs. The three codebooks have 10, 20 and 40 vectors and average rates of about 3, 4, and 5 bits per vector, respectively. Consequently, the first codebook has larger average quantization distortion at a lower rate, whereas the last codebook has smaller average quantization distortion at a higher rate. Given the weighting matrix W_ltp and LTP vector b, the weighted rate-distortion measure for a codebook vector cb_i with rate r_i is give by

+ <figure align="center">

+ <artwork align="center">

+ <![CDATA[

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

+]]>

+ </artwork>

+ </figure>

+ where u is a fixed, heuristically-determined parameter balancing the distortion and rate. Which codebook gives the best performance for a given LTP vector depends on the weighting matrix for that LTP vector. For example, for a low valued W_ltp, it is advantageous to use the codebook with 10 vectors as it has a lower average rate. For a large W_ltp, on the other hand, it is often better to use the codebook with 40 vectors, as it is more likely to contain the best codebook vector.

+ The weighting matrix W_ltp depends mostly on two aspects of the input signal. The first is the periodicity of the signal; the more periodic the larger W_ltp. The second is the change in signal energy in the current subframe, relative to the signal one pitch lag earlier. A decaying energy leads to a larger W_ltp than an increasing energy. Both aspects 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.

+ </t>

+

+ <t>

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

+ </t>

+ </section>

+

+

+ <section title='Noise Shaping Quantizer'>

+ <t>

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

+ </t>

+ <t>

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

+ </t>

+

+ </section>

+

+ <section title='Range Encoder'>

+ <t>

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

+ </t>

+

+ <section title='Bitstream Encoding Details'>

+ <t>

+ TBD.

+ </t>

+ </section>

+ </section>

+ </section>

+

+

+<section title="CELT Encoder">

+<t>

+Copy from CELT draft.

</t>

-</section>

-

+<section anchor="forward-mdct" title="Forward MDCT">

-<section anchor="synthesis" title="Synthesis">

-<t>

-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 (<xref target="inverse-mdct"></xref>) and the weighted overlap-add are applied and the signal is stored in the <spanx style="emph">synthesis

-buffer</spanx>.

-The encoder MAY omit this step of the processing if it does not need the decoded output.

+<t>The MDCT implementation has no special characteristics. The

+input is a windowed signal (after pre-emphasis) of 2*N samples and the output is N

+frequency-domain samples. A <spanx style="emph">low-overlap</spanx> 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 low-overlap window is created by zero-padding the basic window and inserting ones in the middle, such that the resulting window still satisfies power complementarity. The MDCT is computed in mdct_forward() (mdct.c), which includes the windowing operation and a scaling of 2/N.

</t>

</section>

-<section anchor="vbr" title="Variable Bitrate (VBR)">

+<section anchor="normalization" title="Bands and Normalization">

<t>

-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 source-controlled variable bitrate (VBR). Support for VBR is OPTIONAL for the encoder, but a decoder MUST be prepared to decode a stream that changes its bit-rate dynamically. The method used to vary the bit-rate in VBR mode is left to the implementor, as long as each frame can be decoded by the reference decoder.

+The MDCT output is divided into bands that are designed to match the ear's critical

+bands for the smallest (2.5ms) frame size. The larger frame sizes use integer

+multiplies of the 2.5ms layout. For each band, the encoder

+computes the energy that will later be encoded. Each band is then normalized by the

+square root of the <spanx style="strong">non-quantized</spanx> energy, such that each band now forms a unit vector X.

+The energy and the normalization are computed by compute_band_energies()

- original value of ftb was not greater than 8, then t is decoded with

- t = ec_decode(ft), and the decoder state is updated with the

- three-tuple (t,t+1,ft).

+After the coarse energy quantization and encoding, the bit allocation is computed

+(<xref target="allocation"></xref>) 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_i-1]. The mapping between f

+and the correction applied to the coarse energy is equal to (f+1/2)/2^B_i - 1/2. Fine

+energy quantization is implemented in quant_fine_energy()

+(quant_bands.c).

</t>

-</section>

-<section anchor="decoder-tell" title="Current Bit Usage">

<t>

- The bit allocation routines in CELT need to be able to determine a

- conservative upper bound on the number of bits that have been used

- to decode from the current frame thus far. This drives allocation

- decisions which must match those made in the encoder. This is

- computed in the reference implementation to fractional bit precision

- by the function ec_dec_tell() (rangedec.c). Like all

- operations in the range decoder, it must be implemented in a

- bit-exact manner, and must produce exactly the same value returned by

- ec_enc_tell() after encoding the same symbols.

-</t>

-</section>

-

-</section>

-

- <section anchor='outline_decoder' title='SILK Decoder'>

- <t>

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

- </t>

- <section title="Decoder Modules">

- <t>

- An overview of the decoder is given in <xref target="decoder_figure" />.

- <figure align="center" anchor="decoder_figure">

- <artwork align="center">

- <![CDATA[

-

- +---------+ +------------+

--->| Range |--->| Decode |---------------------------+

- 1 | Decoder | 2 | Parameters |----------+ 5 |

- +---------+ +------------+ 4 | |

- 3 | | |

- \/ \/ \/

- +------------+ +------------+ +------------+

- | Generate |-->| LTP |-->| LPC |-->

- | Excitation | | Synthesis | | Synthesis | 6

- +------------+ +------------+ +------------+

-

-1: Range encoded bitstream

-2: Coded parameters

-3: Pulses and gains

-4: Pitch lags and LTP coefficients

-5: LPC coefficients

-6: Decoded signal

-]]>

- </artwork>

- <postamble>Decoder block diagram.</postamble>

- </figure>

- </t>

-

- <section title='Range Decoder'>

- <t>

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

- </t>

- </section>

-

- <section title='Decode Parameters'>

- <t>

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

- </t>

-

- <t>

- When a voiced frame is decoded and LTP codebook selection and indices are received, LTP coefficients are decoded using the selected codebook by choosing the vector that corresponds to the given codebook index in that codebook. This is done for each of the four subframes.

- The LPC coefficients are decoded from the LSF codebook by first adding the chosen vectors, one vector from each stage of the codebook. The resulting LSF vector is stabilized using the same method that was used in the encoder, see

- <xref target='lsf_stabilizer_overview_section' />. The LSF coefficients are then converted to LPC coefficients, and passed on to the LPC synthesis filter.

- </t>

- </section>

-

- <section title='Generate Excitation'>

- <t>

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

- </t>

- </section>

-

- <section title='LTP Synthesis'>

- <t>

- 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

- <figure align="center">

- <artwork align="center">

- <![CDATA[

- d

- __

-e_LPC(n) = e(n) + \ e(n - L - i) * b_i,

- /_

- i=-d

-]]>

- </artwork>

- </figure>

- using the pitch lag L, and the decoded LTP coefficients b_i.

+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 (<xref target="allocation"></xref>) 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).

+</t>

- For unvoiced speech, the output signal is simply a copy of the excitation signal, i.e., e_LPC(n) = e(n).

- </t>

- </section>

+</section> <!-- fine energy -->

- <section title='LPC Synthesis'>

- <t>

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

- <figure align="center">

- <artwork align="center">

- <![CDATA[

- d_LPC

- __

-y(n) = e_LPC(n) + \ e_LPC(n - i) * a_i,

- /_

- i=1

-]]>

- </artwork>

- </figure>

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

- </t>

- </section>

- </section>

- </section>

+</section> <!-- Energy quant -->

-<section title="CELT Decoder">

-<t>

-Insert decoder figure.

+<section anchor="allocation" title="Bit Allocation">

+<t>Bit allocation is performed based only on information available to both

+the encoder and decoder. The same calculations are performed in a bit-exact

+manner in both the encoder and decoder to ensure that the result is always

+exactly the same. Any mismatch causes corruption of the decoded output.

+The allocation is computed by compute_allocation() (rate.c),

+which is used in both the encoder and the decoder.</t>

+

+<t>For a given band, the bit allocation is nearly constant across

+frames that use the same number of bits for Q1, yielding a

+pre-defined signal-to-mask ratio (SMR) for each band. Because the

+bands each have a width of one Bark, this is equivalent to modeling the

+masking occurring within each critical band, while ignoring inter-band

+masking and tone-vs-noise characteristics. While this is not an

+optimal bit allocation, it provides good results without requiring the

+transmission of any allocation information. Additionally, the encoder

+is able to signal alterations to the implicit allocation via

+two means: There is an entropy coded tilt parameter can be used to tilt the

+allocation to favor low or high frequencies, and there is a boost parameter

+which can be used to shift large amounts of additional precision into

+individual bands.

</t>

+

<t>

-The decoder extracts information from the range-coded bit-stream in the same order

-as it was encoded by the encoder. 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.

+For every encoded or decoded frame, a target allocation must be computed

+using the projected allocation. In the reference implementation this is

+performed by compute_allocation() (rate.c).

+The target computation begins by calculating the available space as the

+number of eighth-bits which can be fit in the frame after Q1 is stored according

+to the range coder (ec_tell_frac()) and reserving one eighth-bit.

+Then the two projected prototype allocations whose sums multiplied by 8 are nearest

+to that value are determined. These two projected prototype allocations are then interpolated

+derived from the current allocation is entropy coded to represent the relative gains of each side of

+the split and the entire quantization process is recursively applied.

+Multiple levels of splitting may be applied upto a frame size dependent limit.

+The same recursive mechanism is applied for the joint coding of stereo

+audio.

</t>

</section>

-<section anchor="inverse-mdct" title="Inverse MDCT">

-<t>The inverse MDCT implementation has no special characteristics. The

-input is N frequency-domain samples and the output is 2*N time-domain

-samples, while scaling by 1/2. The output is windowed using the same window

-as the encoder. The IMDCT and windowing are performed by mdct_backward

-(mdct.c). If a time-domain pre-emphasis

-window was applied in the encoder, the (inverse) time-domain de-emphasis window

-is applied on the IMDCT result. After the overlap-add process,

-the signal is de-emphasized using the inverse of the pre-emphasis filter

-used in the encoder: 1/A(z)=1/(1-alpha_p*z^-1).

+</section>

+

+

+<section anchor="stereo" title="Stereo support">

+<t>

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

+</t>

+

+<t>

+The main difference between mono and stereo coding is the PVQ coding of the normalized vectors. In stereo mode, a normalized mid-side (M-S) 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=L-R and no longer have unit norm.

+</t>

+

+<t>

+From M and S, an angular parameter theta=2/pi*atan2(||S||, ||M||) is computed. The theta parameter is converted to a Q14 fixed-point 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 bit-exact manner since both the encoder and decoder rely on it to infer the bit allocation.

+</t>

+<t>

+Let m=M/||M|| and s=S/||S||; m and s are separately encoded with the PVQ encoder described in <xref target="pvq"></xref>. The number of bits allocated to m and s depends on the value of itheta.

-Packet loss concealment (PLC) is an optional decoder-side feature which

-SHOULD be included when transmitting over an unreliable channel. Because

-PLC is not part of the bit-stream, there are several possible ways to

-implement PLC with different complexity/quality trade-offs. The PLC in

-the reference implementation finds a periodicity in the decoded

-signal and repeats the windowed waveform using the pitch offset. The windowed

-waveform is overlapped in such a way as to preserve the time-domain aliasing

-cancellation with the previous frame and the next frame. This is implemented

-in celt_decode_lost() (mdct.c).

+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 (<xref target="inverse-mdct"></xref>) and the weighted overlap-add are applied and the signal is stored in the <spanx style="emph">synthesis

+buffer</spanx>.

+The encoder MAY omit this step of the processing if it does not need the decoded output.

+</t>

+</section>

+

+<section anchor="vbr" title="Variable Bitrate (VBR)">

+<t>

+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 source-controlled variable bitrate (VBR). Support for VBR is OPTIONAL for the encoder, but a decoder MUST be prepared to decode a stream that changes its bit-rate dynamically. The method used to vary the bit-rate in VBR mode is left to the implementor, as long as each frame can be decoded by the reference decoder.