eaaee24084ddd3331453165afbfea3a4b1136618
[speexdsp.git] / doc / manual.lyx
1 #LyX 1.2 created this file. For more info see http://www.lyx.org/
2 \lyxformat 220
3 \textclass article
4 \language english
5 \inputencoding auto
6 \fontscheme default
7 \graphics default
8 \float_placement h
9 \paperfontsize default
10 \spacing single 
11 \papersize Default
12 \paperpackage a4
13 \use_geometry 0
14 \use_amsmath 0
15 \use_natbib 0
16 \use_numerical_citations 0
17 \paperorientation portrait
18 \secnumdepth 3
19 \tocdepth 3
20 \paragraph_separation indent
21 \defskip medskip
22 \quotes_language english
23 \quotes_times 2
24 \papercolumns 1
25 \papersides 1
26 \paperpagestyle headings
27
28 \layout Title
29
30 The Speex Codec Manual
31 \newline 
32 (draft for Speex 1.0beta3)
33 \layout Author
34
35 Jean-Marc Valin
36 \layout Standard
37 \pagebreak_top 
38 Copyright (c) 2002 Jean-Marc Valin.
39 \layout Standard
40
41 Permission is granted to copy, distribute and/or modify this document under
42  the terms of the GNU Free Documentation License, Version 1.1 or any later
43  version published by the Free Software Foundation; with no Invariant Section,
44  with no Front-Cover Texts, and with no Back-Cover.
45  A copy of the license is included in the section entitled "GNU Free Documentati
46 on License".
47  
48 \layout Section*
49
50 Disclaimer
51 \layout Standard
52
53 This document is meant to provide useful information on the Speex codec
54  but there is absolutely no warranty regarding usefulness or correctness
55  of the information provided.
56  Also, some techniques used in Speex are said to be 
57 \begin_inset Quotes eld
58 \end_inset 
59
60 similar
61 \begin_inset Quotes erd
62 \end_inset 
63
64  to techniques used in known codecs.
65  This should not be understood as an acknowledgment that Speex is using
66  any patented algorithm used in these codecs, but merely that comprehension
67  of Speex can be facilitated by thinking that the principles of operation
68  are the same or similar.
69  Of course, there's also the obligatory 
70 \begin_inset Quotes eld
71 \end_inset 
72
73 all trademarks are property of their respective owner
74 \begin_inset Quotes erd
75 \end_inset 
76
77 .
78 \layout Standard
79 \pagebreak_top \pagebreak_bottom 
80
81 \begin_inset LatexCommand \tableofcontents{}
82
83 \end_inset 
84
85
86 \layout Standard
87 \pagebreak_bottom 
88
89 \begin_inset FloatList table
90
91 \end_inset 
92
93
94 \layout Section
95
96 Introduction to Speex
97 \layout Standard
98
99 The Speex project (
100 \family typewriter 
101 http://www.speex.org/
102 \family default 
103 ) has been started because there was a need for a speech codec that was
104  open-source and free from software patents.
105  These are essential conditions for being used by any open-source software.
106  There is already Vorbis that does general audio, but it is not really suitable
107  for speech.
108  Also, unlike many other speech codecs, Speex is not targeted at cell phones
109  (not many open-source cell phones anyway :-) ) but rather voice over IP
110  (VoIP) and file-based compression.
111  
112 \layout Standard
113
114 As design goals, we wanted to have a codec that would allowed both very
115  good quality speech and low bit-rate (unfortunately not at the same time!),
116  which led us to developing a codec with multiple bit-rates.
117  Of course very good quality also meant we had to do wideband (16 kHz sampling
118  rate) in addition to narrowband (telephone quality, 8 kHz sampling rate).
119 \layout Standard
120
121 Designing for VoIP instead of cell phone use means that Speex must be robust
122  to lost packets, but not to corrupted ones since packets either arrive
123  unaltered or don't arrive at all.
124  Also, the idea was to have a reasonnable complexity and memory requirement
125  without compromising too much on the efficiency of the codec.
126 \layout Standard
127
128 All this led us to the choice of CELP
129 \begin_inset LatexCommand \index{CELP}
130
131 \end_inset 
132
133  as the encoding technique to use for Speex.
134  One of the main reasons is that CELP has long proved that it could do the
135  job and scale well to both low bit-rates (think DoD CELP @ 4.8 kbps) and
136  high bit-rates (think G.728 @ 16 kbps).
137  
138 \layout Standard
139
140 The main characteristics can be summerized as follows:
141 \layout Itemize
142
143 Free software/open-source
144 \begin_inset LatexCommand \index{open-source}
145
146 \end_inset 
147
148 , patent
149 \begin_inset LatexCommand \index{patent}
150
151 \end_inset 
152
153  and royalty-free
154 \layout Itemize
155
156 Integration of wideband
157 \begin_inset LatexCommand \index{wideband}
158
159 \end_inset 
160
161  and narrowband
162 \begin_inset LatexCommand \index{narrowband}
163
164 \end_inset 
165
166  in the same bit-stream
167 \layout Itemize
168
169 Wide range of bit-rates available
170 \layout Itemize
171
172 Dynamic bit-rate switching and Variable Bit-Rate
173 \begin_inset LatexCommand \index{variable bit-rate}
174
175 \end_inset 
176
177  (VBR)
178 \layout Itemize
179
180 Voice Activity Detection
181 \begin_inset LatexCommand \index{voice activity detection}
182
183 \end_inset 
184
185  (VAD, integrated with VBR)
186 \layout Itemize
187
188 Variable complexity
189 \begin_inset LatexCommand \index{complexity}
190
191 \end_inset 
192
193
194 \layout Itemize
195
196 Ultra-wideband mode at 32 kHz (up to 48 kHz)
197 \layout Itemize
198
199 Intensity stereo encoding option
200 \layout Section
201 \pagebreak_top 
202 Introduction to CELP Coding
203 \begin_inset LatexCommand \index{CELP}
204
205 \end_inset 
206
207
208 \layout Standard
209
210 Speex is based on CELP, which stands for Code Excited Linear Prediction.
211  This section attempts to introduce the principles behind CELP, so if you
212  are already familiar with CELP, you can safely skip to section 
213 \begin_inset LatexCommand \ref{sec:Speex-narrowband-mode}
214
215 \end_inset 
216
217 .
218  The CELP technique is based on three ideas:
219 \layout Enumerate
220
221 The use of a linear prediction (LP) model to model the vocal tract
222 \layout Enumerate
223
224 The use of (adaptive and fixed) codebook entries as input (excitation) of
225  the LP model
226 \layout Enumerate
227
228 The search performed in closed-loop in a 
229 \begin_inset Quotes eld
230 \end_inset 
231
232 perceptually weighted domain
233 \begin_inset Quotes erd
234 \end_inset 
235
236
237 \layout Subsection
238
239 Linear Prediction (LPC)
240 \begin_inset LatexCommand \index{linear prediction}
241
242 \end_inset 
243
244
245 \layout Standard
246
247
248 \begin_inset Formula \[
249 y(n)=\sum _{i=1}^{N}a_{i}x(n-i)\]
250
251 \end_inset 
252
253
254 \begin_inset Formula \[
255 e(n)=x(n)-y(n)=x(n)-\sum _{i=1}^{N}a_{i}x(n-i)\]
256
257 \end_inset 
258
259
260 \begin_inset Formula \[
261 E=\sum _{n=0}^{L-1}\left[e(n)\right]^{2}=\sum _{n=0}^{L-1}\left[x(n)-\sum _{i=1}^{N}a_{i}x(n-i)\right]^{2}\]
262
263 \end_inset 
264
265
266 \begin_inset Formula \[
267 \frac{\partial E}{\partial a_{i}}=\frac{\partial }{\partial a_{i}}\sum _{n=0}^{L-1}\left[x(n)-\sum _{i=1}^{N}a_{i}x(n-i)\right]^{2}=0\]
268
269 \end_inset 
270
271
272 \layout Standard
273
274 The 
275 \begin_inset Formula $a_{i}$
276 \end_inset 
277
278  filter coefficients are computed using the Levinson-Durbin
279 \begin_inset LatexCommand \index{Levinson-Durbin}
280
281 \end_inset 
282
283  algorithm, which starts from the auto-correlation
284 \begin_inset LatexCommand \index{auto-correlation}
285
286 \end_inset 
287
288  
289 \begin_inset Formula $R(m)$
290 \end_inset 
291
292  of the signal 
293 \begin_inset Formula $x(n)$
294 \end_inset 
295
296 .
297 \layout Standard
298
299
300 \begin_inset Formula \[
301 R(m)=\sum _{i=0}^{N-1}x(i)x(i-m)\]
302
303 \end_inset 
304
305
306 \layout Standard
307
308 For an order 
309 \begin_inset Formula $N$
310 \end_inset 
311
312  filter, we have:
313 \begin_inset Formula \[
314 \mathbf{R}=\left[\begin{array}{cccc}
315  R(0) & R(1) & \cdots  & R(N-1)\\
316  R(1) & R(0) & \cdots  & R(N-2)\\
317  \vdots  & \vdots  & \ddots  & \vdots \\
318  R(N-1) & R(N-2) & \cdots  & R(0)\end{array}
319 \right]\]
320
321 \end_inset 
322
323
324 \begin_inset Formula \[
325 \mathbf{r}=\left[\begin{array}{c}
326  R(1)\\
327  R(2)\\
328  \vdots \\
329  R(N)\end{array}
330 \right]\]
331
332 \end_inset 
333
334
335 \layout Standard
336
337 The filter coefficients 
338 \begin_inset Formula $a_{i}$
339 \end_inset 
340
341  are found by solving the system 
342 \begin_inset Formula $\mathbf{Ra}=\mathbf{r}$
343 \end_inset 
344
345 .
346  What the Levinson-Durbin algorithm does here is making the solution to
347  the problem 
348 \begin_inset Formula $\mathcal{O}\left(N^{2}\right)$
349 \end_inset 
350
351  instead of 
352 \begin_inset Formula $\mathcal{O}\left(N^{3}\right)$
353 \end_inset 
354
355  by exploiting the fact that matrix 
356 \begin_inset Formula $\mathbf{R}$
357 \end_inset 
358
359  is toeplitz hermitian.
360  Also, it can be proved that all the roots of 
361 \begin_inset Formula $A(z)$
362 \end_inset 
363
364  are withing the unit circle, which means that 
365 \begin_inset Formula $1/A(z)$
366 \end_inset 
367
368  is always stable.
369  This is in theory; in practice because of finite precision, there are two
370  commonly used techniques to make sure we have a stable filter.
371  First, we multiply 
372 \begin_inset Formula $R(0)$
373 \end_inset 
374
375  by a number slightly above one (such as 1.0001), which is equivalent to
376  adding noise to the signal.
377  Also, we can apply a window the the auto-correlation, which is equivalent
378  to filtering in the frequency domain, reducing sharp resonances.
379 \layout Standard
380
381 The linear prediction model represents each speech sample as linear combination
382  of past samples, plus an error signal called the excitation (or residual).
383 \begin_inset Formula \[
384 x(n)=\sum _{i=1}^{N}a_{i}x(n-i)+e(n)\]
385
386 \end_inset 
387
388
389 \layout Standard
390
391 In the 
392 \emph on 
393 z
394 \emph default 
395 -domain, this can be expressed as
396 \layout Standard
397
398
399 \begin_inset Formula \[
400 x(z)=\frac{1}{A(z)}\: e(z)\]
401
402 \end_inset 
403
404
405 \layout Standard
406
407 where 
408 \begin_inset Formula $A(z)$
409 \end_inset 
410
411  is defined as
412 \layout Standard
413
414
415 \begin_inset Formula \[
416 A(z)=1-\sum _{i=1}^{N}a_{i}z^{-i}\]
417
418 \end_inset 
419
420
421 \layout Standard
422
423 We usually refer to 
424 \begin_inset Formula $A(z)$
425 \end_inset 
426
427  as the analysis filter and 
428 \begin_inset Formula $1/A(z)$
429 \end_inset 
430
431  as the synthesis filter.
432 \layout Standard
433
434 Because LPC coefficients have very little robustness to quantization, they
435  are converted to Line Spectral Pair
436 \begin_inset LatexCommand \index{line spectral pair}
437
438 \end_inset 
439
440  (LSP) coefficients which have a much better behaviour with quantization,
441  one of them being that it's easy to keep the filter stable.
442  
443 \layout Subsection
444
445 Pitch Prediction
446 \begin_inset LatexCommand \index{pitch}
447
448 \end_inset 
449
450
451 \layout Standard
452
453 During voiced segments, the speech signal is very periodic, so it is possible
454  to take advantage of that by expressing the excitation signal 
455 \begin_inset Formula $e(n)$
456 \end_inset 
457
458  as
459 \layout Standard
460
461
462 \begin_inset Formula \[
463 e(n)=\beta e(n-T)+c(n)\]
464
465 \end_inset 
466
467
468 \layout Standard
469
470 where 
471 \begin_inset Formula $T$
472 \end_inset 
473
474  is the pitch period, 
475 \begin_inset Formula $\beta $
476 \end_inset 
477
478  is the pitch gain and 
479 \begin_inset Formula $c(n)$
480 \end_inset 
481
482  is taken from the 
483 \emph on 
484 innovation codebook
485 \emph default 
486 .
487  In the 
488 \emph on 
489 z
490 \emph default 
491 -domain, the excitation can be expressed as:
492 \layout Standard
493
494
495 \begin_inset Formula \[
496 e(z)=\frac{1}{1-\beta z^{-T}}\: c(z)\]
497
498 \end_inset 
499
500
501 \layout Subsection
502
503 Innovation Codebook
504 \layout Standard
505
506 This is where most of the bits in a CELP codec are allocated.
507  It represents the information that couldn't be obtained either from linear
508  prediction or pitch prediction.
509 \layout Subsection
510
511 Analysis-by-Synthesis and Error Weighting
512 \begin_inset LatexCommand \index{error weighting}
513
514 \end_inset 
515
516
517 \begin_inset LatexCommand \index{analysis-by-synthesis}
518
519 \end_inset 
520
521
522 \layout Standard
523
524 Most (if not all) modern audio codecs attempt to 
525 \emph on 
526 shape
527 \emph default 
528  the noise so that it is the hardest to detect with the ear.
529  That means that more noise can be tolerated in parts of the spectrum that
530  are louder and 
531 \emph on 
532 vice versa
533 \emph default 
534 .
535  That's why the error is minimized for the perceptually weighted signal
536 \begin_inset Formula \[
537 X_{w}(z)=W(z)X(z)\]
538
539 \end_inset 
540
541 where 
542 \begin_inset Formula $W(z)$
543 \end_inset 
544
545  is the weighting filter, usually of the form
546 \layout Standard
547
548
549 \begin_inset Formula \begin{equation}
550 W(z)=\frac{A\left(\frac{z}{\gamma _{1}}\right)}{A\left(\frac{z}{\gamma _{2}}\right)}\label{eq:weighting_filter}\end{equation}
551
552 \end_inset 
553
554
555 \layout Standard
556
557 with control parameters 
558 \begin_inset Formula $\gamma _{1}>\gamma _{2}$
559 \end_inset 
560
561 .
562  If the noise is white in the perceptually weighted domain, then in the
563  signal domain its spectral shape will be of the form
564 \begin_inset Formula \[
565 A_{noise}(z)=\frac{1}{W(z)}=\frac{A\left(\frac{z}{\gamma _{2}}\right)}{A\left(\frac{z}{\gamma _{1}}\right)}\]
566
567 \end_inset 
568
569
570 \layout Standard
571
572 If a filter 
573 \begin_inset Formula $A(z)$
574 \end_inset 
575
576  has (complex) poles at 
577 \begin_inset Formula $p_{i}$
578 \end_inset 
579
580  in the 
581 \begin_inset Formula $z$
582 \end_inset 
583
584 -plane, the filter 
585 \begin_inset Formula $A(z/\gamma )$
586 \end_inset 
587
588  filter will have its poles at 
589 \begin_inset Formula $p_{i}^{'}=\gamma p_{i}$
590 \end_inset 
591
592 , making it a flatter version of 
593 \begin_inset Formula $A(z)$
594 \end_inset 
595
596 .
597 \layout Section
598 \pagebreak_top 
599 Speex narrowband mode
600 \begin_inset LatexCommand \label{sec:Speex-narrowband-mode}
601
602 \end_inset 
603
604
605 \begin_inset LatexCommand \index{narrowband}
606
607 \end_inset 
608
609
610 \layout Standard
611
612 This section looks at how Speex works for narrowband (
613 \begin_inset Formula $8\: \mathrm{kHz}$
614 \end_inset 
615
616  sampling rate) operation.
617  The frame size for this mode is 
618 \begin_inset Formula $20\: \mathrm{ms}$
619 \end_inset 
620
621 , corresponding to 160 samples.
622  Each frame is also subdivided into 4 sub-frames of 40 samples each.
623 \layout Standard
624
625 Also many design decisions were based on the original goals and assumptions:
626 \layout Itemize
627
628 Minimizing the amount of information extracted from past frames (for robustness
629  to packet loss)
630 \layout Itemize
631
632 Dynamically-selectable codebooks (LSP, pitch and innovation)
633 \layout Itemize
634
635 G.728-like fixed codebooks (without backward-adaptive grains because of patent
636  issues)
637 \layout Subsection
638
639 LPC Analysis
640 \begin_inset LatexCommand \index{linear prediction}
641
642 \end_inset 
643
644
645 \layout Standard
646
647 An LPC analysis is first performed on a (Hamming) window that spans all
648  the current frame and half a frame in advance.
649  The LPC coefficients are then converted to Line Spectral Pair
650 \begin_inset LatexCommand \index{line spectral pair}
651
652 \end_inset 
653
654  (LSP), a representation that is more robust to quantization.
655  The LSP's are considered to be associated to the 
656 \begin_inset Formula $4^{th}$
657 \end_inset 
658
659  sub-frames and the LSP's associated to the first 3 sub-frames are linearly
660  interpolated using the current and previous LSP's.
661 \layout Standard
662
663 The LSP's are encoded using 30 bits for higher quality modes and 18 bits
664  for lower quality, through the use of a multi-stage split-vector quantizer.
665  For the lower quality modes, the 10 coefficients are first quantized with
666  6 bits and the error is then divided in two 5-coefficient sub-vectors.
667  Each of them is quantized with 6 bits, for a total of 18 bits.
668  For the higher quality modes, the remaining error on both sub-vectors is
669  turther quantized with 6 bits each, for a total of 30 bits.
670 \layout Standard
671
672 The perceptual weighting filter 
673 \begin_inset Formula $W(z)$
674 \end_inset 
675
676  used by Speex is derived from the LPC analysis and corresponds to the one
677  described by eq.
678  
679 \begin_inset LatexCommand \ref{eq:weighting_filter}
680
681 \end_inset 
682
683  with 
684 \begin_inset Formula $\gamma _{1}=0.9$
685 \end_inset 
686
687  and 
688 \begin_inset Formula $\gamma _{2}=0.6$
689 \end_inset 
690
691 .
692  We can use the unquantized 
693 \begin_inset Formula $A(z)$
694 \end_inset 
695
696  filter since the weighting filter is only used in the encoder.
697 \layout Subsection
698
699 Pitch Prediction (adaptive codebook)
700 \begin_inset LatexCommand \index{pitch}
701
702 \end_inset 
703
704
705 \layout Standard
706
707 Speex uses a 3-tap prediction for pitch.
708  That is, 
709 \layout Standard
710
711
712 \begin_inset Formula \[
713 e(n)=\beta _{0}e(n-T-1)+\beta _{1}e(n-T)+\beta _{2}e(n-T+1)+c(n)\]
714
715 \end_inset 
716
717
718 \layout Standard
719
720 where 
721 \begin_inset Formula $T$
722 \end_inset 
723
724  is the pitch period and the 
725 \begin_inset Formula $\beta _{i}$
726 \end_inset 
727
728  are the prediction (filter) taps.
729  The period and quantized gains are determined in closed loop.
730 \layout Subsection
731
732 Innovation Codebook
733 \layout Standard
734
735 In Speex, the innovation signal is quantized using shape-only vector quantizatio
736 n (VQ).
737  That means that the codebooks that are used represent both the shape and
738  the gain at the same time.
739  This save many bits that would otherwise be allocated for a separate gain
740  at the price of a slight increase in complexity.
741  Except for the absence of (backward-adaptive) gain, the technique used
742  in Speex is similar to G.728 (LD-CELP).
743  However since we do not have a low-delay constraint, the search can be
744  made more 
745 \begin_inset Quotes eld
746 \end_inset 
747
748 global
749 \begin_inset Quotes erd
750 \end_inset 
751
752  and make use of the whole information available for a sub-frame.
753 \layout Subsection
754
755 Bit allocation
756 \layout Standard
757
758 There are 7 different narrowband bit-rates defined for Speex, ranging from
759  200 bps to 18.15 kbps, although the modes below 5.9 kbps should not be used
760  for speech.
761  The bit-allocation for each mode is detailed in table 
762 \begin_inset LatexCommand \ref{cap:bits-narrowband}
763
764 \end_inset 
765
766 .
767  Each frame starts with the mode ID encoded with 4 bits which allows a range
768  from 0 to 15, though only the first 7 values are used (the others are reserved).
769  The parameters are listed in the table in the order they are packed in
770  the bit-stream.
771  All frame-based parameters are packed before sub-frame parameters.
772  The parameters for a certain sub-frame are all packed before the following
773  sub-frame is packed.
774  Note that the 
775 \begin_inset Quotes eld
776 \end_inset 
777
778 OL
779 \begin_inset Quotes erd
780 \end_inset 
781
782  in the parameter description means the the parameter is an open loop estimation
783  based on the whole frame.
784 \layout Standard
785
786
787 \begin_inset Float table
788 placement htbp
789 wide true
790 collapsed false
791
792 \layout Standard
793
794
795 \begin_inset  Tabular
796 <lyxtabular version="3" rows="12" columns="10">
797 <features>
798 <column alignment="center" valignment="top" leftline="true" width="0pt">
799 <column alignment="center" valignment="top" leftline="true" width="0pt">
800 <column alignment="center" valignment="top" leftline="true" width="0pt">
801 <column alignment="center" valignment="top" leftline="true" width="0pt">
802 <column alignment="center" valignment="top" leftline="true" width="0pt">
803 <column alignment="center" valignment="top" leftline="true" width="0pt">
804 <column alignment="center" valignment="top" leftline="true" width="0pt">
805 <column alignment="center" valignment="top" leftline="true" width="0pt">
806 <column alignment="center" valignment="top" leftline="true" width="0pt">
807 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
808 <row topline="true" bottomline="true">
809 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
810 \begin_inset Text
811
812 \layout Standard
813
814 Parameter
815 \end_inset 
816 </cell>
817 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
818 \begin_inset Text
819
820 \layout Standard
821
822 Update rate
823 \end_inset 
824 </cell>
825 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
826 \begin_inset Text
827
828 \layout Standard
829
830 0
831 \end_inset 
832 </cell>
833 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
834 \begin_inset Text
835
836 \layout Standard
837
838 1
839 \end_inset 
840 </cell>
841 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
842 \begin_inset Text
843
844 \layout Standard
845
846 2
847 \end_inset 
848 </cell>
849 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
850 \begin_inset Text
851
852 \layout Standard
853
854 3
855 \end_inset 
856 </cell>
857 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
858 \begin_inset Text
859
860 \layout Standard
861
862 4
863 \end_inset 
864 </cell>
865 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
866 \begin_inset Text
867
868 \layout Standard
869
870 5
871 \end_inset 
872 </cell>
873 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
874 \begin_inset Text
875
876 \layout Standard
877
878 6
879 \end_inset 
880 </cell>
881 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
882 \begin_inset Text
883
884 \layout Standard
885
886 7
887 \end_inset 
888 </cell>
889 </row>
890 <row topline="true">
891 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
892 \begin_inset Text
893
894 \layout Standard
895
896 Wideband bit
897 \end_inset 
898 </cell>
899 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
900 \begin_inset Text
901
902 \layout Standard
903
904 frame
905 \end_inset 
906 </cell>
907 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
908 \begin_inset Text
909
910 \layout Standard
911
912 1
913 \end_inset 
914 </cell>
915 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
916 \begin_inset Text
917
918 \layout Standard
919
920 1
921 \end_inset 
922 </cell>
923 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
924 \begin_inset Text
925
926 \layout Standard
927
928 1
929 \end_inset 
930 </cell>
931 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
932 \begin_inset Text
933
934 \layout Standard
935
936 1
937 \end_inset 
938 </cell>
939 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
940 \begin_inset Text
941
942 \layout Standard
943
944 1
945 \end_inset 
946 </cell>
947 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
948 \begin_inset Text
949
950 \layout Standard
951
952 1
953 \end_inset 
954 </cell>
955 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
956 \begin_inset Text
957
958 \layout Standard
959
960 1
961 \end_inset 
962 </cell>
963 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
964 \begin_inset Text
965
966 \layout Standard
967
968 1
969 \end_inset 
970 </cell>
971 </row>
972 <row topline="true">
973 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
974 \begin_inset Text
975
976 \layout Standard
977
978 Mode ID
979 \end_inset 
980 </cell>
981 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
982 \begin_inset Text
983
984 \layout Standard
985
986 frame
987 \end_inset 
988 </cell>
989 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
990 \begin_inset Text
991
992 \layout Standard
993
994 4
995 \end_inset 
996 </cell>
997 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
998 \begin_inset Text
999
1000 \layout Standard
1001
1002 4
1003 \end_inset 
1004 </cell>
1005 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1006 \begin_inset Text
1007
1008 \layout Standard
1009
1010 4
1011 \end_inset 
1012 </cell>
1013 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1014 \begin_inset Text
1015
1016 \layout Standard
1017
1018 4
1019 \end_inset 
1020 </cell>
1021 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1022 \begin_inset Text
1023
1024 \layout Standard
1025
1026 4
1027 \end_inset 
1028 </cell>
1029 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1030 \begin_inset Text
1031
1032 \layout Standard
1033
1034 4
1035 \end_inset 
1036 </cell>
1037 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1038 \begin_inset Text
1039
1040 \layout Standard
1041
1042 4
1043 \end_inset 
1044 </cell>
1045 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1046 \begin_inset Text
1047
1048 \layout Standard
1049
1050 4
1051 \end_inset 
1052 </cell>
1053 </row>
1054 <row topline="true">
1055 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1056 \begin_inset Text
1057
1058 \layout Standard
1059
1060 LSP
1061 \end_inset 
1062 </cell>
1063 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1064 \begin_inset Text
1065
1066 \layout Standard
1067
1068 frame
1069 \end_inset 
1070 </cell>
1071 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1072 \begin_inset Text
1073
1074 \layout Standard
1075
1076 0
1077 \end_inset 
1078 </cell>
1079 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1080 \begin_inset Text
1081
1082 \layout Standard
1083
1084 18
1085 \end_inset 
1086 </cell>
1087 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1088 \begin_inset Text
1089
1090 \layout Standard
1091
1092 18
1093 \end_inset 
1094 </cell>
1095 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1096 \begin_inset Text
1097
1098 \layout Standard
1099
1100 18
1101 \end_inset 
1102 </cell>
1103 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1104 \begin_inset Text
1105
1106 \layout Standard
1107
1108 18
1109 \end_inset 
1110 </cell>
1111 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1112 \begin_inset Text
1113
1114 \layout Standard
1115
1116 30
1117 \end_inset 
1118 </cell>
1119 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1120 \begin_inset Text
1121
1122 \layout Standard
1123
1124 30
1125 \end_inset 
1126 </cell>
1127 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1128 \begin_inset Text
1129
1130 \layout Standard
1131
1132 30
1133 \end_inset 
1134 </cell>
1135 </row>
1136 <row topline="true">
1137 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1138 \begin_inset Text
1139
1140 \layout Standard
1141
1142 OL pitch
1143 \end_inset 
1144 </cell>
1145 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1146 \begin_inset Text
1147
1148 \layout Standard
1149
1150 frame
1151 \end_inset 
1152 </cell>
1153 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1154 \begin_inset Text
1155
1156 \layout Standard
1157
1158 0
1159 \end_inset 
1160 </cell>
1161 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1162 \begin_inset Text
1163
1164 \layout Standard
1165
1166 7
1167 \end_inset 
1168 </cell>
1169 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1170 \begin_inset Text
1171
1172 \layout Standard
1173
1174 7
1175 \end_inset 
1176 </cell>
1177 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1178 \begin_inset Text
1179
1180 \layout Standard
1181
1182 0
1183 \end_inset 
1184 </cell>
1185 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1186 \begin_inset Text
1187
1188 \layout Standard
1189
1190 0
1191 \end_inset 
1192 </cell>
1193 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1194 \begin_inset Text
1195
1196 \layout Standard
1197
1198 0
1199 \end_inset 
1200 </cell>
1201 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1202 \begin_inset Text
1203
1204 \layout Standard
1205
1206 0
1207 \end_inset 
1208 </cell>
1209 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1210 \begin_inset Text
1211
1212 \layout Standard
1213
1214 0
1215 \end_inset 
1216 </cell>
1217 </row>
1218 <row topline="true">
1219 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1220 \begin_inset Text
1221
1222 \layout Standard
1223
1224 OL pitch gain
1225 \end_inset 
1226 </cell>
1227 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1228 \begin_inset Text
1229
1230 \layout Standard
1231
1232 frame
1233 \end_inset 
1234 </cell>
1235 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1236 \begin_inset Text
1237
1238 \layout Standard
1239
1240 0
1241 \end_inset 
1242 </cell>
1243 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1244 \begin_inset Text
1245
1246 \layout Standard
1247
1248 4
1249 \end_inset 
1250 </cell>
1251 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1252 \begin_inset Text
1253
1254 \layout Standard
1255
1256 0
1257 \end_inset 
1258 </cell>
1259 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1260 \begin_inset Text
1261
1262 \layout Standard
1263
1264 0
1265 \end_inset 
1266 </cell>
1267 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1268 \begin_inset Text
1269
1270 \layout Standard
1271
1272 0
1273 \end_inset 
1274 </cell>
1275 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1276 \begin_inset Text
1277
1278 \layout Standard
1279
1280 0
1281 \end_inset 
1282 </cell>
1283 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1284 \begin_inset Text
1285
1286 \layout Standard
1287
1288 0
1289 \end_inset 
1290 </cell>
1291 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1292 \begin_inset Text
1293
1294 \layout Standard
1295
1296 0
1297 \end_inset 
1298 </cell>
1299 </row>
1300 <row topline="true">
1301 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1302 \begin_inset Text
1303
1304 \layout Standard
1305
1306 OL Exc gain
1307 \end_inset 
1308 </cell>
1309 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1310 \begin_inset Text
1311
1312 \layout Standard
1313
1314 frame
1315 \end_inset 
1316 </cell>
1317 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1318 \begin_inset Text
1319
1320 \layout Standard
1321
1322 0
1323 \end_inset 
1324 </cell>
1325 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1326 \begin_inset Text
1327
1328 \layout Standard
1329
1330 5
1331 \end_inset 
1332 </cell>
1333 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1334 \begin_inset Text
1335
1336 \layout Standard
1337
1338 5
1339 \end_inset 
1340 </cell>
1341 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1342 \begin_inset Text
1343
1344 \layout Standard
1345
1346 5
1347 \end_inset 
1348 </cell>
1349 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1350 \begin_inset Text
1351
1352 \layout Standard
1353
1354 5
1355 \end_inset 
1356 </cell>
1357 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1358 \begin_inset Text
1359
1360 \layout Standard
1361
1362 5
1363 \end_inset 
1364 </cell>
1365 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1366 \begin_inset Text
1367
1368 \layout Standard
1369
1370 5
1371 \end_inset 
1372 </cell>
1373 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1374 \begin_inset Text
1375
1376 \layout Standard
1377
1378 5
1379 \end_inset 
1380 </cell>
1381 </row>
1382 <row topline="true">
1383 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1384 \begin_inset Text
1385
1386 \layout Standard
1387
1388 Fine pitch
1389 \end_inset 
1390 </cell>
1391 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1392 \begin_inset Text
1393
1394 \layout Standard
1395
1396 sub-frame
1397 \end_inset 
1398 </cell>
1399 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1400 \begin_inset Text
1401
1402 \layout Standard
1403
1404 0
1405 \end_inset 
1406 </cell>
1407 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1408 \begin_inset Text
1409
1410 \layout Standard
1411
1412 0
1413 \end_inset 
1414 </cell>
1415 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1416 \begin_inset Text
1417
1418 \layout Standard
1419
1420 0
1421 \end_inset 
1422 </cell>
1423 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1424 \begin_inset Text
1425
1426 \layout Standard
1427
1428 7
1429 \end_inset 
1430 </cell>
1431 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1432 \begin_inset Text
1433
1434 \layout Standard
1435
1436 7
1437 \end_inset 
1438 </cell>
1439 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1440 \begin_inset Text
1441
1442 \layout Standard
1443
1444 7
1445 \end_inset 
1446 </cell>
1447 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1448 \begin_inset Text
1449
1450 \layout Standard
1451
1452 7
1453 \end_inset 
1454 </cell>
1455 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1456 \begin_inset Text
1457
1458 \layout Standard
1459
1460 7
1461 \end_inset 
1462 </cell>
1463 </row>
1464 <row topline="true">
1465 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1466 \begin_inset Text
1467
1468 \layout Standard
1469
1470 Pitch gain
1471 \end_inset 
1472 </cell>
1473 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1474 \begin_inset Text
1475
1476 \layout Standard
1477
1478 sub-frame
1479 \end_inset 
1480 </cell>
1481 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1482 \begin_inset Text
1483
1484 \layout Standard
1485
1486 0
1487 \end_inset 
1488 </cell>
1489 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1490 \begin_inset Text
1491
1492 \layout Standard
1493
1494 0
1495 \end_inset 
1496 </cell>
1497 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1498 \begin_inset Text
1499
1500 \layout Standard
1501
1502 5
1503 \end_inset 
1504 </cell>
1505 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1506 \begin_inset Text
1507
1508 \layout Standard
1509
1510 5
1511 \end_inset 
1512 </cell>
1513 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1514 \begin_inset Text
1515
1516 \layout Standard
1517
1518 5
1519 \end_inset 
1520 </cell>
1521 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1522 \begin_inset Text
1523
1524 \layout Standard
1525
1526 7
1527 \end_inset 
1528 </cell>
1529 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1530 \begin_inset Text
1531
1532 \layout Standard
1533
1534 7
1535 \end_inset 
1536 </cell>
1537 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1538 \begin_inset Text
1539
1540 \layout Standard
1541
1542 7
1543 \end_inset 
1544 </cell>
1545 </row>
1546 <row topline="true">
1547 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1548 \begin_inset Text
1549
1550 \layout Standard
1551
1552 Innovation gain
1553 \end_inset 
1554 </cell>
1555 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1556 \begin_inset Text
1557
1558 \layout Standard
1559
1560 sub-frame
1561 \end_inset 
1562 </cell>
1563 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1564 \begin_inset Text
1565
1566 \layout Standard
1567
1568 0
1569 \end_inset 
1570 </cell>
1571 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1572 \begin_inset Text
1573
1574 \layout Standard
1575
1576 1
1577 \end_inset 
1578 </cell>
1579 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1580 \begin_inset Text
1581
1582 \layout Standard
1583
1584 0
1585 \end_inset 
1586 </cell>
1587 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1588 \begin_inset Text
1589
1590 \layout Standard
1591
1592 1
1593 \end_inset 
1594 </cell>
1595 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1596 \begin_inset Text
1597
1598 \layout Standard
1599
1600 1
1601 \end_inset 
1602 </cell>
1603 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1604 \begin_inset Text
1605
1606 \layout Standard
1607
1608 3
1609 \end_inset 
1610 </cell>
1611 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1612 \begin_inset Text
1613
1614 \layout Standard
1615
1616 3
1617 \end_inset 
1618 </cell>
1619 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1620 \begin_inset Text
1621
1622 \layout Standard
1623
1624 3
1625 \end_inset 
1626 </cell>
1627 </row>
1628 <row topline="true" bottomline="true">
1629 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1630 \begin_inset Text
1631
1632 \layout Standard
1633
1634 Innovation VQ
1635 \end_inset 
1636 </cell>
1637 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1638 \begin_inset Text
1639
1640 \layout Standard
1641
1642 sub-frame
1643 \end_inset 
1644 </cell>
1645 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1646 \begin_inset Text
1647
1648 \layout Standard
1649
1650 0
1651 \end_inset 
1652 </cell>
1653 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1654 \begin_inset Text
1655
1656 \layout Standard
1657
1658 0
1659 \end_inset 
1660 </cell>
1661 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1662 \begin_inset Text
1663
1664 \layout Standard
1665
1666 16
1667 \end_inset 
1668 </cell>
1669 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1670 \begin_inset Text
1671
1672 \layout Standard
1673
1674 20
1675 \end_inset 
1676 </cell>
1677 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1678 \begin_inset Text
1679
1680 \layout Standard
1681
1682 35
1683 \end_inset 
1684 </cell>
1685 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1686 \begin_inset Text
1687
1688 \layout Standard
1689
1690 48
1691 \end_inset 
1692 </cell>
1693 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1694 \begin_inset Text
1695
1696 \layout Standard
1697
1698 64
1699 \end_inset 
1700 </cell>
1701 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1702 \begin_inset Text
1703
1704 \layout Standard
1705
1706 96
1707 \end_inset 
1708 </cell>
1709 </row>
1710 <row topline="true" bottomline="true">
1711 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1712 \begin_inset Text
1713
1714 \layout Standard
1715
1716 Total
1717 \end_inset 
1718 </cell>
1719 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1720 \begin_inset Text
1721
1722 \layout Standard
1723
1724 frame
1725 \end_inset 
1726 </cell>
1727 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1728 \begin_inset Text
1729
1730 \layout Standard
1731
1732 5
1733 \end_inset 
1734 </cell>
1735 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1736 \begin_inset Text
1737
1738 \layout Standard
1739
1740 43
1741 \end_inset 
1742 </cell>
1743 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1744 \begin_inset Text
1745
1746 \layout Standard
1747
1748 119
1749 \end_inset 
1750 </cell>
1751 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1752 \begin_inset Text
1753
1754 \layout Standard
1755
1756 160
1757 \end_inset 
1758 </cell>
1759 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1760 \begin_inset Text
1761
1762 \layout Standard
1763
1764 220
1765 \end_inset 
1766 </cell>
1767 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1768 \begin_inset Text
1769
1770 \layout Standard
1771
1772 300
1773 \end_inset 
1774 </cell>
1775 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1776 \begin_inset Text
1777
1778 \layout Standard
1779
1780 364
1781 \end_inset 
1782 </cell>
1783 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1784 \begin_inset Text
1785
1786 \layout Standard
1787
1788 492
1789 \end_inset 
1790 </cell>
1791 </row>
1792 </lyxtabular>
1793
1794 \end_inset 
1795
1796
1797 \layout Caption
1798
1799 Bit allocation for narrowband modes
1800 \begin_inset LatexCommand \label{cap:bits-narrowband}
1801
1802 \end_inset 
1803
1804
1805 \end_inset 
1806
1807
1808 \layout Standard
1809
1810 So far, no MOS (Mean Opinion Score
1811 \begin_inset LatexCommand \index{mean opinion score}
1812
1813 \end_inset 
1814
1815 ) subjective evaluation has been performed for Speex.
1816  In order to give an idea of the quality achivable with it, table 
1817 \begin_inset LatexCommand \ref{cap:quality_vs_bps}
1818
1819 \end_inset 
1820
1821  presents my own subjective opinion on it.
1822  It sould be noted that different people will perceive the quality differently
1823  and that the person that designed the codec often has a bias (one way or
1824  another) when it comes to subjective evaluation.
1825  Last thing, it should be noted that for most codecs (including Speex) encoding
1826  quality sometimes varies depending on the input.
1827  Note that the complexity is only approximate (withing 0.5 mflops and using
1828  the lowers complexity setting).
1829  Decoding requires approximately 0.5 mflops
1830 \begin_inset LatexCommand \index{complexity}
1831
1832 \end_inset 
1833
1834  in most modes (1 mflops with perceptual enhancement).
1835 \layout Standard
1836
1837
1838 \begin_inset Float table
1839 placement htbp
1840 wide true
1841 collapsed false
1842
1843 \layout Standard
1844
1845
1846 \begin_inset  Tabular
1847 <lyxtabular version="3" rows="17" columns="4">
1848 <features>
1849 <column alignment="center" valignment="top" leftline="true" width="0pt">
1850 <column alignment="center" valignment="top" leftline="true" width="0pt">
1851 <column alignment="center" valignment="top" leftline="true" width="0pt">
1852 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
1853 <row topline="true" bottomline="true">
1854 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1855 \begin_inset Text
1856
1857 \layout Standard
1858
1859 Mode
1860 \end_inset 
1861 </cell>
1862 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1863 \begin_inset Text
1864
1865 \layout Standard
1866
1867 Bit-rate
1868 \begin_inset LatexCommand \index{bit-rate}
1869
1870 \end_inset 
1871
1872  (bps)
1873 \end_inset 
1874 </cell>
1875 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1876 \begin_inset Text
1877
1878 \layout Standard
1879
1880 mflops
1881 \begin_inset LatexCommand \index{complexity}
1882
1883 \end_inset 
1884
1885
1886 \end_inset 
1887 </cell>
1888 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1889 \begin_inset Text
1890
1891 \layout Standard
1892
1893 Quality/description
1894 \end_inset 
1895 </cell>
1896 </row>
1897 <row topline="true">
1898 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1899 \begin_inset Text
1900
1901 \layout Standard
1902
1903 0
1904 \end_inset 
1905 </cell>
1906 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1907 \begin_inset Text
1908
1909 \layout Standard
1910
1911 250
1912 \end_inset 
1913 </cell>
1914 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1915 \begin_inset Text
1916
1917 \layout Standard
1918
1919 N/A
1920 \end_inset 
1921 </cell>
1922 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1923 \begin_inset Text
1924
1925 \layout Standard
1926
1927 No sound (VBR only)
1928 \end_inset 
1929 </cell>
1930 </row>
1931 <row topline="true">
1932 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1933 \begin_inset Text
1934
1935 \layout Standard
1936
1937 1
1938 \end_inset 
1939 </cell>
1940 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1941 \begin_inset Text
1942
1943 \layout Standard
1944
1945 2,150
1946 \end_inset 
1947 </cell>
1948 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1949 \begin_inset Text
1950
1951 \layout Standard
1952
1953 6
1954 \end_inset 
1955 </cell>
1956 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1957 \begin_inset Text
1958
1959 \layout Standard
1960
1961 Vocoder (mostly for comfort noise)
1962 \end_inset 
1963 </cell>
1964 </row>
1965 <row topline="true">
1966 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1967 \begin_inset Text
1968
1969 \layout Standard
1970
1971 2
1972 \end_inset 
1973 </cell>
1974 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1975 \begin_inset Text
1976
1977 \layout Standard
1978
1979 5,950
1980 \end_inset 
1981 </cell>
1982 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1983 \begin_inset Text
1984
1985 \layout Standard
1986
1987 9
1988 \end_inset 
1989 </cell>
1990 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1991 \begin_inset Text
1992
1993 \layout Standard
1994
1995 Very noticeable artifacts/noise, good intelligibility
1996 \end_inset 
1997 </cell>
1998 </row>
1999 <row topline="true">
2000 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2001 \begin_inset Text
2002
2003 \layout Standard
2004
2005 3
2006 \end_inset 
2007 </cell>
2008 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2009 \begin_inset Text
2010
2011 \layout Standard
2012
2013 8,000
2014 \end_inset 
2015 </cell>
2016 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2017 \begin_inset Text
2018
2019 \layout Standard
2020
2021 10
2022 \end_inset 
2023 </cell>
2024 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2025 \begin_inset Text
2026
2027 \layout Standard
2028
2029 Artifacts/noise sometimes noticeable
2030 \end_inset 
2031 </cell>
2032 </row>
2033 <row topline="true">
2034 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2035 \begin_inset Text
2036
2037 \layout Standard
2038
2039 4
2040 \end_inset 
2041 </cell>
2042 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2043 \begin_inset Text
2044
2045 \layout Standard
2046
2047 11,000
2048 \end_inset 
2049 </cell>
2050 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2051 \begin_inset Text
2052
2053 \layout Standard
2054
2055 14
2056 \end_inset 
2057 </cell>
2058 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2059 \begin_inset Text
2060
2061 \layout Standard
2062
2063 Artifacts usually noticeable only with headphones
2064 \end_inset 
2065 </cell>
2066 </row>
2067 <row topline="true">
2068 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2069 \begin_inset Text
2070
2071 \layout Standard
2072
2073 5
2074 \end_inset 
2075 </cell>
2076 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2077 \begin_inset Text
2078
2079 \layout Standard
2080
2081 15,000
2082 \end_inset 
2083 </cell>
2084 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2085 \begin_inset Text
2086
2087 \layout Standard
2088
2089 11
2090 \end_inset 
2091 </cell>
2092 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2093 \begin_inset Text
2094
2095 \layout Standard
2096
2097 Need good headphones to tell the difference
2098 \end_inset 
2099 </cell>
2100 </row>
2101 <row topline="true">
2102 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2103 \begin_inset Text
2104
2105 \layout Standard
2106
2107 6
2108 \end_inset 
2109 </cell>
2110 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2111 \begin_inset Text
2112
2113 \layout Standard
2114
2115 18,200
2116 \end_inset 
2117 </cell>
2118 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2119 \begin_inset Text
2120
2121 \layout Standard
2122
2123 17.5
2124 \end_inset 
2125 </cell>
2126 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2127 \begin_inset Text
2128
2129 \layout Standard
2130
2131 Hard to tell the difference even with good headphones
2132 \end_inset 
2133 </cell>
2134 </row>
2135 <row topline="true">
2136 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2137 \begin_inset Text
2138
2139 \layout Standard
2140
2141 7
2142 \end_inset 
2143 </cell>
2144 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2145 \begin_inset Text
2146
2147 \layout Standard
2148
2149 24,600
2150 \end_inset 
2151 </cell>
2152 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2153 \begin_inset Text
2154
2155 \layout Standard
2156
2157 14.5
2158 \end_inset 
2159 </cell>
2160 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2161 \begin_inset Text
2162
2163 \layout Standard
2164
2165 Completely transparent for voice, good quality music
2166 \end_inset 
2167 </cell>
2168 </row>
2169 <row topline="true">
2170 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2171 \begin_inset Text
2172
2173 \layout Standard
2174
2175 8
2176 \end_inset 
2177 </cell>
2178 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2179 \begin_inset Text
2180
2181 \layout Standard
2182
2183 N/A
2184 \end_inset 
2185 </cell>
2186 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2187 \begin_inset Text
2188
2189 \layout Standard
2190
2191 N/A
2192 \end_inset 
2193 </cell>
2194 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2195 \begin_inset Text
2196
2197 \layout Standard
2198
2199 (Tones/DTMF to be implemented)
2200 \end_inset 
2201 </cell>
2202 </row>
2203 <row topline="true">
2204 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2205 \begin_inset Text
2206
2207 \layout Standard
2208
2209 9
2210 \end_inset 
2211 </cell>
2212 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2213 \begin_inset Text
2214
2215 \layout Standard
2216
2217 N/A
2218 \end_inset 
2219 </cell>
2220 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2221 \begin_inset Text
2222
2223 \layout Standard
2224
2225 N/A
2226 \end_inset 
2227 </cell>
2228 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2229 \begin_inset Text
2230
2231 \layout Standard
2232
2233 reserved
2234 \end_inset 
2235 </cell>
2236 </row>
2237 <row topline="true">
2238 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2239 \begin_inset Text
2240
2241 \layout Standard
2242
2243 10
2244 \end_inset 
2245 </cell>
2246 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2247 \begin_inset Text
2248
2249 \layout Standard
2250
2251 N/A
2252 \end_inset 
2253 </cell>
2254 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2255 \begin_inset Text
2256
2257 \layout Standard
2258
2259 N/A
2260 \end_inset 
2261 </cell>
2262 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2263 \begin_inset Text
2264
2265 \layout Standard
2266
2267 reserved
2268 \end_inset 
2269 </cell>
2270 </row>
2271 <row topline="true">
2272 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2273 \begin_inset Text
2274
2275 \layout Standard
2276
2277 11
2278 \end_inset 
2279 </cell>
2280 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2281 \begin_inset Text
2282
2283 \layout Standard
2284
2285 N/A
2286 \end_inset 
2287 </cell>
2288 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2289 \begin_inset Text
2290
2291 \layout Standard
2292
2293 N/A
2294 \end_inset 
2295 </cell>
2296 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2297 \begin_inset Text
2298
2299 \layout Standard
2300
2301 reserved
2302 \end_inset 
2303 </cell>
2304 </row>
2305 <row topline="true">
2306 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2307 \begin_inset Text
2308
2309 \layout Standard
2310
2311 12
2312 \end_inset 
2313 </cell>
2314 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2315 \begin_inset Text
2316
2317 \layout Standard
2318
2319 N/A
2320 \end_inset 
2321 </cell>
2322 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2323 \begin_inset Text
2324
2325 \layout Standard
2326
2327 N/A
2328 \end_inset 
2329 </cell>
2330 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2331 \begin_inset Text
2332
2333 \layout Standard
2334
2335 reserved
2336 \end_inset 
2337 </cell>
2338 </row>
2339 <row topline="true">
2340 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2341 \begin_inset Text
2342
2343 \layout Standard
2344
2345 13
2346 \end_inset 
2347 </cell>
2348 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2349 \begin_inset Text
2350
2351 \layout Standard
2352
2353 N/A
2354 \end_inset 
2355 </cell>
2356 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2357 \begin_inset Text
2358
2359 \layout Standard
2360
2361 N/A
2362 \end_inset 
2363 </cell>
2364 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2365 \begin_inset Text
2366
2367 \layout Standard
2368
2369 Application-defined, interpreted by callback or skipped
2370 \end_inset 
2371 </cell>
2372 </row>
2373 <row topline="true">
2374 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2375 \begin_inset Text
2376
2377 \layout Standard
2378
2379 14
2380 \end_inset 
2381 </cell>
2382 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2383 \begin_inset Text
2384
2385 \layout Standard
2386
2387 N/A
2388 \end_inset 
2389 </cell>
2390 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2391 \begin_inset Text
2392
2393 \layout Standard
2394
2395 N/A
2396 \end_inset 
2397 </cell>
2398 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2399 \begin_inset Text
2400
2401 \layout Standard
2402
2403 Speex in-band signaling
2404 \end_inset 
2405 </cell>
2406 </row>
2407 <row topline="true" bottomline="true">
2408 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2409 \begin_inset Text
2410
2411 \layout Standard
2412
2413 15
2414 \end_inset 
2415 </cell>
2416 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2417 \begin_inset Text
2418
2419 \layout Standard
2420
2421 N/A
2422 \end_inset 
2423 </cell>
2424 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2425 \begin_inset Text
2426
2427 \layout Standard
2428
2429 N/A
2430 \end_inset 
2431 </cell>
2432 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2433 \begin_inset Text
2434
2435 \layout Standard
2436
2437 Terminator code
2438 \end_inset 
2439 </cell>
2440 </row>
2441 </lyxtabular>
2442
2443 \end_inset 
2444
2445
2446 \layout Caption
2447
2448 Quality versus bit-rate
2449 \begin_inset LatexCommand \label{cap:quality_vs_bps}
2450
2451 \end_inset 
2452
2453
2454 \end_inset 
2455
2456
2457 \layout Subsection
2458
2459 Perceptual enhancement
2460 \begin_inset LatexCommand \index{perceptual enhancement}
2461
2462 \end_inset 
2463
2464
2465 \layout Standard
2466
2467 This part of the codec only applies to the decoder and can even be changed
2468  without affecting inter-operability.
2469  For that reason, the implementation provided and described here should
2470  only be considered as a reference implementation.
2471  The enhancement system is devided in two parts.
2472  First, the synthesis filter 
2473 \begin_inset Formula $S(z)=1/A(z)$
2474 \end_inset 
2475
2476  is replaced by an enhanced filter
2477 \begin_inset Formula \[
2478 S'(z)=\frac{A\left(z/a_{2}\right)A\left(z/a_{3}\right)}{A\left(z\right)A\left(z/a_{1}\right)}\]
2479
2480 \end_inset 
2481
2482 where 
2483 \begin_inset Formula $a_{1}$
2484 \end_inset 
2485
2486  and 
2487 \begin_inset Formula $a_{2}$
2488 \end_inset 
2489
2490  depend on the mode in use and 
2491 \begin_inset Formula $a_{3}=\frac{1}{r}\left(1-\frac{1-ra_{1}}{1-ra_{2}}\right)$
2492 \end_inset 
2493
2494  with 
2495 \begin_inset Formula $r=.9$
2496 \end_inset 
2497
2498 .
2499  The second part of the enhancement consists of using a comb filter to enhance
2500  the pitch in the excitation domain.
2501  
2502 \layout Section
2503 \pagebreak_top 
2504 Speex wideband mode (sub-band CELP)
2505 \begin_inset LatexCommand \index{wideband}
2506
2507 \end_inset 
2508
2509
2510 \layout Standard
2511
2512 For wideband, the Speex approach uses a 
2513 \emph on 
2514 q
2515 \emph default 
2516 uadrature 
2517 \emph on 
2518 m
2519 \emph default 
2520 irror 
2521 \emph on 
2522 f
2523 \emph default 
2524 ilter
2525 \begin_inset LatexCommand \index{quadrature mirror filter}
2526
2527 \end_inset 
2528
2529  (QMF) to split the band in two.
2530  The 16 kHz signal is thus divided into two 8 kHz signals, one representing
2531  the low band (0-4 kHz), the other the high band (4-8 kHz).
2532  The low band is encoded with the narrowband mode described in section 
2533 \begin_inset LatexCommand \ref{sec:Speex-narrowband-mode}
2534
2535 \end_inset 
2536
2537  in such a way that the resulting 
2538 \begin_inset Quotes eld
2539 \end_inset 
2540
2541 embedded narrowband bit-stream
2542 \begin_inset Quotes erd
2543 \end_inset 
2544
2545  can also be decoded with the narrowband decoder.
2546  Since the low band encoding has already been described only the high band
2547  encoding is described in this section.
2548 \layout Subsection
2549
2550 Linear Prediction
2551 \layout Standard
2552
2553 The linear prediction part used for the high-band is very similar to what
2554  is done for narrowband.
2555  The only difference is that we use only 12 bits to encode the high-band
2556  LSP's using a multi-stage vector quantizer (MSVQ).
2557  The first level quantizes the 10 coefficients with 6 bits and the error
2558  is then quantized using 6 bits too.
2559 \layout Subsection
2560
2561 Pitch Prediction
2562 \layout Standard
2563
2564 That part is easy: there's no pitch prediction for the high-band.
2565  There are two reasons for that.
2566  First, there is usually little harmonic structure in this band (above 4
2567  kHz).
2568  Second, it would be very hard to implement since the QMF folds the 4-8
2569  kHz band into 4-0 kHz (reversing the frequency axis), which means that
2570  the location of the harmonics are no longer at multiples of the fundamental
2571  (pitch).
2572 \layout Subsection
2573
2574 Excitation Quantization
2575 \layout Standard
2576
2577 The high-band excitation is coded in the same way as for narrowband.
2578  
2579 \layout Subsection
2580
2581 Bit allocation
2582 \layout Standard
2583
2584 For the wideband mode, all the narrowband frame is packed before the high-band
2585  is encoded.
2586  The narrowband part of the bit-stream is as defined in table 
2587 \begin_inset LatexCommand \ref{cap:bits-narrowband}
2588
2589 \end_inset 
2590
2591 .
2592  The high-band follows, as described in table 
2593 \begin_inset LatexCommand \ref{cap:bits-wideband}
2594
2595 \end_inset 
2596
2597 .
2598  This also means that a wideband frame may be correctly decoded by a narrowband
2599  decoder with the only caveat that if more than one frame is packed in the
2600  same packet, the decoder will need to skip the high-band parts in order
2601  to sync with the bit-stream.
2602 \layout Standard
2603
2604
2605 \begin_inset Float table
2606 placement htbp
2607 wide true
2608 collapsed false
2609
2610 \layout Standard
2611
2612
2613 \begin_inset  Tabular
2614 <lyxtabular version="3" rows="7" columns="7">
2615 <features>
2616 <column alignment="center" valignment="top" leftline="true" width="0pt">
2617 <column alignment="center" valignment="top" leftline="true" width="0pt">
2618 <column alignment="center" valignment="top" leftline="true" width="0pt">
2619 <column alignment="center" valignment="top" leftline="true" width="0pt">
2620 <column alignment="center" valignment="top" leftline="true" width="0pt">
2621 <column alignment="center" valignment="top" leftline="true" width="0pt">
2622 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
2623 <row topline="true" bottomline="true">
2624 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2625 \begin_inset Text
2626
2627 \layout Standard
2628
2629 Parameter
2630 \end_inset 
2631 </cell>
2632 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2633 \begin_inset Text
2634
2635 \layout Standard
2636
2637 Update rate
2638 \end_inset 
2639 </cell>
2640 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2641 \begin_inset Text
2642
2643 \layout Standard
2644
2645 0
2646 \end_inset 
2647 </cell>
2648 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2649 \begin_inset Text
2650
2651 \layout Standard
2652
2653 1
2654 \end_inset 
2655 </cell>
2656 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2657 \begin_inset Text
2658
2659 \layout Standard
2660
2661 2
2662 \end_inset 
2663 </cell>
2664 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2665 \begin_inset Text
2666
2667 \layout Standard
2668
2669 3
2670 \end_inset 
2671 </cell>
2672 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2673 \begin_inset Text
2674
2675 \layout Standard
2676
2677 4
2678 \end_inset 
2679 </cell>
2680 </row>
2681 <row topline="true">
2682 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2683 \begin_inset Text
2684
2685 \layout Standard
2686
2687 Wideband bit
2688 \end_inset 
2689 </cell>
2690 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2691 \begin_inset Text
2692
2693 \layout Standard
2694
2695 frame
2696 \end_inset 
2697 </cell>
2698 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2699 \begin_inset Text
2700
2701 \layout Standard
2702
2703 1
2704 \end_inset 
2705 </cell>
2706 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2707 \begin_inset Text
2708
2709 \layout Standard
2710
2711 1
2712 \end_inset 
2713 </cell>
2714 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2715 \begin_inset Text
2716
2717 \layout Standard
2718
2719 1
2720 \end_inset 
2721 </cell>
2722 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2723 \begin_inset Text
2724
2725 \layout Standard
2726
2727 1
2728 \end_inset 
2729 </cell>
2730 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2731 \begin_inset Text
2732
2733 \layout Standard
2734
2735 1
2736 \end_inset 
2737 </cell>
2738 </row>
2739 <row topline="true">
2740 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2741 \begin_inset Text
2742
2743 \layout Standard
2744
2745 Mode ID
2746 \end_inset 
2747 </cell>
2748 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2749 \begin_inset Text
2750
2751 \layout Standard
2752
2753 frame
2754 \end_inset 
2755 </cell>
2756 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2757 \begin_inset Text
2758
2759 \layout Standard
2760
2761 3
2762 \end_inset 
2763 </cell>
2764 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2765 \begin_inset Text
2766
2767 \layout Standard
2768
2769 3
2770 \end_inset 
2771 </cell>
2772 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2773 \begin_inset Text
2774
2775 \layout Standard
2776
2777 3
2778 \end_inset 
2779 </cell>
2780 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2781 \begin_inset Text
2782
2783 \layout Standard
2784
2785 3
2786 \end_inset 
2787 </cell>
2788 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2789 \begin_inset Text
2790
2791 \layout Standard
2792
2793 3
2794 \end_inset 
2795 </cell>
2796 </row>
2797 <row topline="true">
2798 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2799 \begin_inset Text
2800
2801 \layout Standard
2802
2803 LSP
2804 \end_inset 
2805 </cell>
2806 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2807 \begin_inset Text
2808
2809 \layout Standard
2810
2811 frame
2812 \end_inset 
2813 </cell>
2814 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2815 \begin_inset Text
2816
2817 \layout Standard
2818
2819 0
2820 \end_inset 
2821 </cell>
2822 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2823 \begin_inset Text
2824
2825 \layout Standard
2826
2827 12
2828 \end_inset 
2829 </cell>
2830 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2831 \begin_inset Text
2832
2833 \layout Standard
2834
2835 12
2836 \end_inset 
2837 </cell>
2838 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2839 \begin_inset Text
2840
2841 \layout Standard
2842
2843 12
2844 \end_inset 
2845 </cell>
2846 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2847 \begin_inset Text
2848
2849 \layout Standard
2850
2851 12
2852 \end_inset 
2853 </cell>
2854 </row>
2855 <row topline="true">
2856 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2857 \begin_inset Text
2858
2859 \layout Standard
2860
2861 Excitation gain
2862 \end_inset 
2863 </cell>
2864 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2865 \begin_inset Text
2866
2867 \layout Standard
2868
2869 sub-frame
2870 \end_inset 
2871 </cell>
2872 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2873 \begin_inset Text
2874
2875 \layout Standard
2876
2877 0
2878 \end_inset 
2879 </cell>
2880 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2881 \begin_inset Text
2882
2883 \layout Standard
2884
2885 5
2886 \end_inset 
2887 </cell>
2888 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2889 \begin_inset Text
2890
2891 \layout Standard
2892
2893 4
2894 \end_inset 
2895 </cell>
2896 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2897 \begin_inset Text
2898
2899 \layout Standard
2900
2901 4
2902 \end_inset 
2903 </cell>
2904 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2905 \begin_inset Text
2906
2907 \layout Standard
2908
2909 4
2910 \end_inset 
2911 </cell>
2912 </row>
2913 <row topline="true" bottomline="true">
2914 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2915 \begin_inset Text
2916
2917 \layout Standard
2918
2919 Excitation VQ
2920 \end_inset 
2921 </cell>
2922 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2923 \begin_inset Text
2924
2925 \layout Standard
2926
2927 sub-frame
2928 \end_inset 
2929 </cell>
2930 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2931 \begin_inset Text
2932
2933 \layout Standard
2934
2935 0
2936 \end_inset 
2937 </cell>
2938 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2939 \begin_inset Text
2940
2941 \layout Standard
2942
2943 0
2944 \end_inset 
2945 </cell>
2946 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2947 \begin_inset Text
2948
2949 \layout Standard
2950
2951 20
2952 \end_inset 
2953 </cell>
2954 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2955 \begin_inset Text
2956
2957 \layout Standard
2958
2959 40
2960 \end_inset 
2961 </cell>
2962 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2963 \begin_inset Text
2964
2965 \layout Standard
2966
2967 80
2968 \end_inset 
2969 </cell>
2970 </row>
2971 <row topline="true" bottomline="true">
2972 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2973 \begin_inset Text
2974
2975 \layout Standard
2976
2977 Total
2978 \end_inset 
2979 </cell>
2980 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2981 \begin_inset Text
2982
2983 \layout Standard
2984
2985 frame
2986 \end_inset 
2987 </cell>
2988 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2989 \begin_inset Text
2990
2991 \layout Standard
2992
2993 4
2994 \end_inset 
2995 </cell>
2996 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2997 \begin_inset Text
2998
2999 \layout Standard
3000
3001 36
3002 \end_inset 
3003 </cell>
3004 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3005 \begin_inset Text
3006
3007 \layout Standard
3008
3009 112
3010 \end_inset 
3011 </cell>
3012 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3013 \begin_inset Text
3014
3015 \layout Standard
3016
3017 192
3018 \end_inset 
3019 </cell>
3020 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3021 \begin_inset Text
3022
3023 \layout Standard
3024
3025 352
3026 \end_inset 
3027 </cell>
3028 </row>
3029 </lyxtabular>
3030
3031 \end_inset 
3032
3033
3034 \layout Caption
3035
3036 Bit allocation for high-band in wideband mode
3037 \begin_inset LatexCommand \label{cap:bits-wideband}
3038
3039 \end_inset 
3040
3041
3042 \end_inset 
3043
3044
3045 \layout Section
3046 \pagebreak_top 
3047 Command-line encoder/decoder
3048 \layout Standard
3049
3050 The base Speex distribution includes a command-line encoder (
3051 \emph on 
3052 speexenc
3053 \emph default 
3054 ) and decoder (
3055 \emph on 
3056 speexdec
3057 \emph default 
3058 ).
3059 \layout Subsection
3060
3061
3062 \emph on 
3063 speexenc
3064 \begin_inset LatexCommand \index{speexenc}
3065
3066 \end_inset 
3067
3068
3069 \layout Standard
3070
3071 The encoder takes the following options:
3072 \layout Description
3073
3074 --narrowband\SpecialChar ~
3075 (-n) Tell Speex to treat the input as narrowband (8 kHz).
3076  This is the default
3077 \layout Description
3078
3079 --wideband\SpecialChar ~
3080 (-w) Tell Speex to treat the input as wideband (16 kHz)
3081 \layout Description
3082
3083 --ultra-wideband\SpecialChar ~
3084 (-u) Tell Speex to treat the input as 
3085 \begin_inset Quotes eld
3086 \end_inset 
3087
3088 ultra-wideband
3089 \begin_inset Quotes erd
3090 \end_inset 
3091
3092  (32 kHz)
3093 \layout Description
3094
3095 --quality\SpecialChar ~
3096 n Set the encoding quality (0-10), default is 3
3097 \layout Description
3098
3099 --bitrate\SpecialChar ~
3100 n Encoding bit-rate (use bit-rate n or lower) 
3101 \layout Description
3102
3103 --vbr Enable VBR (Variable Bit-Rate), disabled by default
3104 \layout Description
3105
3106 --nframes\SpecialChar ~
3107 n Pack n frames in each Ogg packet (this saves space at low bit-rates)
3108 \layout Description
3109
3110 --comp\SpecialChar ~
3111 n Set encoding speed/quality tradeoff.
3112  The higher the value of n, the slower the encoding (default is 3)
3113 \layout Description
3114
3115 -V Verbose operation, print bit-rate currently in use
3116 \layout Description
3117
3118 --help\SpecialChar ~
3119 (-h) Print the help
3120 \layout Description
3121
3122 --version\SpecialChar ~
3123 (-v) Print version information
3124 \layout Subsubsection*
3125
3126 Speex comments
3127 \layout Description
3128
3129 --comment Add the given string as an extra comment.
3130  This may be used multiple times.
3131  
3132 \layout Description
3133
3134 --author Author of this track.
3135  
3136 \layout Description
3137
3138 --title Title for this track.
3139  
3140 \layout Subsubsection*
3141
3142 Raw input options
3143 \layout Description
3144
3145 --rate\SpecialChar ~
3146 n Sampling rate for raw input
3147 \layout Description
3148
3149 --stereo Consider raw input as stereo 
3150 \layout Description
3151
3152 --le Raw input is little-endian 
3153 \layout Description
3154
3155 --be Raw input is big-endian 
3156 \layout Description
3157
3158 --8bit Raw input is 8-bit unsigned 
3159 \layout Description
3160
3161 --16bit Raw input is 16-bit signed 
3162 \layout Subsection
3163
3164
3165 \emph on 
3166 speexdec
3167 \begin_inset LatexCommand \index{speexdec}
3168
3169 \end_inset 
3170
3171
3172 \layout Standard
3173
3174 The decoder takes the following options:
3175 \layout Description
3176
3177 --enh enable post-filter
3178 \layout Description
3179
3180 --no-enh disable post-filter (default)
3181 \layout Description
3182
3183 --force-nb Force decoding in narrowband 
3184 \layout Description
3185
3186 --force-wb Force decoding in wideband 
3187 \layout Description
3188
3189 --force-uwb Force decoding in ultra-wideband 
3190 \layout Description
3191
3192 --mono Force decoding in mono 
3193 \layout Description
3194
3195 --stereo Force decoding in stereo 
3196 \layout Description
3197
3198 --packet-loss\SpecialChar ~
3199 n Simulate n % random packet loss
3200 \layout Description
3201
3202 -V Verbose operation, print bit-rate currently in use
3203 \layout Description
3204
3205 --help\SpecialChar ~
3206 (-h) Print the help
3207 \layout Description
3208
3209 --version\SpecialChar ~
3210 (-v) Print version information
3211 \layout Section
3212 \pagebreak_top 
3213 Programming with Speex (the libspeex
3214 \begin_inset LatexCommand \index{libspeex}
3215
3216 \end_inset 
3217
3218  API
3219 \begin_inset LatexCommand \index{API}
3220
3221 \end_inset 
3222
3223 )
3224 \layout Subsection
3225
3226 Encoding
3227 \layout Standard
3228
3229 In order to encode speech using Speex, you first need to:
3230 \layout LyX-Code
3231
3232 #include <speex.h>
3233 \layout Standard
3234
3235 You then need to declare a Speex bit-packing struct
3236 \layout LyX-Code
3237
3238 SpeexBits bits;
3239 \layout Standard
3240
3241 and a Speex encoder state
3242 \layout LyX-Code
3243
3244 void *enc_state;
3245 \layout Standard
3246
3247 The two are initialized by:
3248 \layout LyX-Code
3249
3250 speex_bits_init(&bits);
3251 \layout LyX-Code
3252
3253 enc_state = speex_encoder_init(&speex_nb_mode);
3254 \layout Standard
3255
3256 For wideband coding, 
3257 \emph on 
3258 speex_nb_mode
3259 \emph default 
3260  will be replaced by 
3261 \emph on 
3262 speex_wb_mode
3263 \emph default 
3264 .
3265  In most cases, you will need to know the frame size used by the mode you
3266  are using.
3267  You can get that value in the 
3268 \emph on 
3269 frame_size
3270 \emph default 
3271  variable with:
3272 \layout LyX-Code
3273
3274 speex_encoder_ctl(enc_state,SPEEX_GET_FRAME_SIZE,&frame_size);
3275 \layout Standard
3276
3277 Once the initialization is done, for every input frame:
3278 \layout LyX-Code
3279
3280 speex_bits_reset(&bits);
3281 \layout LyX-Code
3282
3283 speex_encode(enc_state, input_frame, &bits);
3284 \layout LyX-Code
3285
3286 nbBytes = speex_bits_write(&bits, byte_ptr, MAX_NB_BYTES);
3287 \layout Standard
3288
3289 where 
3290 \emph on 
3291 input_frame
3292 \emph default 
3293  is a 
3294 \emph on 
3295 (float *)
3296 \emph default 
3297  pointing to the beginning of a speech frame, 
3298 \emph on 
3299 byte_ptr
3300 \emph default 
3301  is a 
3302 \emph on 
3303 (char *)
3304 \emph default 
3305  where the encoded frame will be written, 
3306 \emph on 
3307 MAX_NB_BYTES
3308 \emph default 
3309  is the maximum number of bytes that can be written to 
3310 \emph on 
3311 byte_ptr
3312 \emph default 
3313  without causing an overflow and 
3314 \emph on 
3315 nbBytes
3316 \emph default 
3317  is the number of bytes actually written to 
3318 \emph on 
3319 byte_ptr
3320 \emph default 
3321  (the encoded size in bytes).
3322  Before calling speex_bits_write, it is possible to find the number of bytes
3323  that need to be written by calling 
3324 \family typewriter 
3325 speex_bits_nbytes(&bits)
3326 \family default 
3327 , which returns a number of bytes.
3328  
3329 \layout Standard
3330
3331 After you're done with the encoding, free all resources with:
3332 \layout LyX-Code
3333
3334 speex_bits_destroy(&bits);
3335 \layout LyX-Code
3336
3337 speex_encoder_destroy(enc_state);
3338 \layout Standard
3339
3340 That's about it for the encoder.
3341  
3342 \layout Subsection
3343
3344 Decoding
3345 \layout Standard
3346
3347 In order to encode speech using Speex, you first need to:
3348 \layout LyX-Code
3349
3350 #include <speex.h>
3351 \layout Standard
3352
3353 You then need to declare a Speex bit-packing struct
3354 \layout LyX-Code
3355
3356 SpeexBits bits;
3357 \layout Standard
3358
3359 and a Speex encoder state
3360 \layout LyX-Code
3361
3362 void *dec_state;
3363 \layout Standard
3364
3365 The two are initialized by:
3366 \layout LyX-Code
3367
3368 speex_bits_init(&bits);
3369 \layout LyX-Code
3370
3371 dec_state = speex_decoder_init(&speex_nb_mode);
3372 \layout Standard
3373
3374 For wideband decoding, 
3375 \emph on 
3376 speex_nb_mode
3377 \emph default 
3378  will be replaced by 
3379 \emph on 
3380 speex_wb_mode
3381 \emph default 
3382 .
3383  You can get that value in the 
3384 \emph on 
3385 frame_size
3386 \emph default 
3387  variable with:
3388 \layout LyX-Code
3389
3390 speex_decoder_ctl(dec_state, SPEEX_GET_FRAME_SIZE, &frame_size); 
3391 \layout Standard
3392
3393 There is also a parameter that can be set for the decoder: whether or not
3394  to use a perceptual post-filter.
3395  This can be set by: 
3396 \layout LyX-Code
3397
3398 speex_decoder_ctl(dec_state, SPEEX_SET_PF, &pf); 
3399 \layout Standard
3400
3401 where pf is an int that with value 0 to have the post-filter disabled and
3402  1 to have it enabled.
3403 \layout Standard
3404
3405 Again, once the decoder initialization is done, for every input frame:
3406 \layout LyX-Code
3407
3408 speex_bits_read_from(&bits, input_bytes, nbBytes);
3409 \layout LyX-Code
3410
3411 speex_decode(st, &bits, output_frame);
3412 \layout Standard
3413
3414 where input_bytes is a 
3415 \emph on 
3416 (char *)
3417 \emph default 
3418  containing the bit-stream data received for a frame, 
3419 \emph on 
3420 nbBytes
3421 \emph default 
3422  is the size (in bytes) of that bit-stream, and 
3423 \emph on 
3424 output_frame
3425 \emph default 
3426  is a 
3427 \emph on 
3428 (float *)
3429 \emph default 
3430  and points to the area where the decoded speech frame will be written.
3431  A NULL value as the first argument indicates that we don't have the bits
3432  for the current frame.
3433  When a frame is lost, the Speex decoder will do its best to "guess" the
3434  correct signal.
3435 \layout Standard
3436
3437 After you're done with the decoding, free all resources with:
3438 \layout LyX-Code
3439
3440 speex_bits_destroy(&bits);
3441 \layout LyX-Code
3442
3443 speex_decoder_destroy(dec_state);
3444 \layout Subsection
3445
3446 Codec Options (speex_*_ctl)
3447 \layout Standard
3448
3449 The Speex encoder and decoder support many options and requests that can
3450  be accessed through the 
3451 \emph on 
3452 speex_encoder_ctl
3453 \emph default 
3454  and 
3455 \emph on 
3456 speex_decoder_ctl
3457 \emph default 
3458  functions.
3459  These functions are similar the the 
3460 \emph on 
3461 ioctl
3462 \emph default 
3463  system call and their prototypes are:
3464 \layout LyX-Code
3465
3466 void speex_encoder_ctl(void *encoder, int request, void *ptr);
3467 \layout LyX-Code
3468
3469 void speex_decoder_ctl(void *encoder, int request, void *ptr);
3470 \layout Standard
3471
3472 The different values of request allowed are (note that some only apply to
3473  the encoder or the decoder):
3474 \layout Description
3475
3476 SPEEX_SET_ENH** Set perceptual enhancer to on (1) or off (0) (integer)
3477 \layout Description
3478
3479 SPEEX_GET_ENH** Get perceptual enhancer status (integer)
3480 \layout Description
3481
3482 SPEEX_GET_FRAME_SIZE Get the frame size used for the current mode (integer)
3483 \layout Description
3484
3485 SPEEX_SET_QUALITY* Set the encoder speech quality (integer 0 to 10)
3486 \layout Description
3487
3488 SPEEX_GET_QUALITY* Get the current encoder speech quality (integer 0 to
3489  10)
3490 \layout Description
3491
3492 SPEEX_SET_MODE*
3493 \begin_inset Formula $\dagger $
3494 \end_inset 
3495
3496
3497 \layout Description
3498
3499 SPEEX_GET_MODE*
3500 \begin_inset Formula $\dagger $
3501 \end_inset 
3502
3503
3504 \layout Description
3505
3506 SPEEX_SET_LOW_MODE*
3507 \begin_inset Formula $\dagger $
3508 \end_inset 
3509
3510
3511 \layout Description
3512
3513 SPEEX_GET_LOW_MODE*
3514 \begin_inset Formula $\dagger $
3515 \end_inset 
3516
3517
3518 \layout Description
3519
3520 SPEEX_SET_HIGH_MODE*
3521 \begin_inset Formula $\dagger $
3522 \end_inset 
3523
3524
3525 \layout Description
3526
3527 SPEEX_GET_HIGH_MODE*
3528 \begin_inset Formula $\dagger $
3529 \end_inset 
3530
3531
3532 \layout Description
3533
3534 SPEEX_SET_VBR* Set variable bit-rate (VBR) to on (1) or off (0) (integer)
3535 \layout Description
3536
3537 SPEEX_GET_VBR* Get variable bit-rate (VBR) status (integer)
3538 \layout Description
3539
3540 SPEEX_SET_VBR_QUALITY* Set the encoder VBR speech quality (integer 0 to
3541  10)
3542 \layout Description
3543
3544 SPEEX_GET_VBR_QUALITY* Get the current encoder VBR speech quality (integer
3545  0 to 10)
3546 \layout Description
3547
3548 SPEEX_SET_COMPLEXITY* Set the CPU resources allowed for the encoder
3549 \layout Description
3550
3551 SPEEX_GET_COMPLEXITY* Get the CPU resources allowed for the encoder
3552 \layout Description
3553
3554 SPEEX_SET_BITRATE* Set the bit-rate to use to the closest value not exceeding
3555  the parameter (integer in bps)
3556 \layout Description
3557
3558 SPEEX_GET_BITRATE Get the current bit-rate in use (integer in bps)
3559 \layout Description
3560
3561 SPEEX_SET_SAMPLING_RATE Set real sampling rate (is used to determine real
3562  bit-rate)
3563 \layout Description
3564
3565 SPEEX_GET_SAMPLING_RATE Get real sampling rate (is used to determine real
3566  bit-rate)
3567 \layout Description
3568
3569 * applies only to the encoder
3570 \layout Description
3571
3572 ** applies only to the decoder
3573 \layout Description
3574
3575
3576 \begin_inset Formula $\dagger $
3577 \end_inset 
3578
3579  normally only used internally
3580 \layout Subsection
3581
3582 Mode queries
3583 \layout Standard
3584
3585 Speex modes have a querry system similar to the speex_encoder_ctl and speex_deco
3586 der_ctl calls.
3587  Since modes are read-only, it is only possible to get information about
3588  a particular mode.
3589  The function used to do that is:
3590 \layout LyX-Code
3591
3592 void speex_mode_query(SpeexMode *mode, int request, void *ptr);
3593 \layout Standard
3594
3595 The admissible values for request are (unless otherwise note, the values
3596  are returned through 
3597 \emph on 
3598 ptr
3599 \emph default 
3600 ):
3601 \layout Description
3602
3603 SPEEX_MODE_FRAME_SIZE Get the frame size (in samples) for the mode
3604 \layout Description
3605
3606 SPEEX_SUBMODE_BITRATE Get the bit-rate for a submode number specified throught
3607  
3608 \emph on 
3609 ptr
3610 \emph default 
3611 .
3612 \layout Subsection
3613
3614 Packing and in-band signalling
3615 \begin_inset LatexCommand \index{in-band signalling}
3616
3617 \end_inset 
3618
3619
3620 \layout Standard
3621
3622 Sometimes it is desirable to pack more than one frame per packet (or other
3623  basic unit of storage).
3624  The proper way to do it is to call speex_encode 
3625 \begin_inset Formula $N$
3626 \end_inset 
3627
3628  times before writing the stream with speex_bits_write.
3629  In cases where the number of frames is not determined by an out-of-band
3630  mechanism, it is possible to include a terminator code.
3631  That terminator consists of the code 15 (decimal) encoded with 5 bits,
3632  as shown in figure 
3633 \begin_inset LatexCommand \ref{cap:quality_vs_bps}
3634
3635 \end_inset 
3636
3637 .
3638  
3639 \layout Standard
3640
3641 It is also possible to send in-band 
3642 \begin_inset Quotes eld
3643 \end_inset 
3644
3645 messages
3646 \begin_inset Quotes erd
3647 \end_inset 
3648
3649  to the other side.
3650  All these messages are encoded as a 
3651 \begin_inset Quotes eld
3652 \end_inset 
3653
3654 pseudo-frame
3655 \begin_inset Quotes erd
3656 \end_inset 
3657
3658  of mode 14 which contain a 4-bit message type code, followed by the message.
3659  Table 
3660 \begin_inset LatexCommand \ref{cap:In-band-signalling-codes}
3661
3662 \end_inset 
3663
3664  lists the available codes, their meaning and the size of the message that
3665  follow.
3666  Most of these messages are requests that are sent to the encoder or decoder
3667  on the other end, which is free to comply or ignore them.
3668  By default, all in-band messages are ignored.
3669 \layout Standard
3670
3671
3672 \begin_inset Float table
3673 placement htbp
3674 wide false
3675 collapsed false
3676
3677 \layout Standard
3678
3679
3680 \begin_inset  Tabular
3681 <lyxtabular version="3" rows="17" columns="3">
3682 <features>
3683 <column alignment="center" valignment="top" leftline="true" width="0pt">
3684 <column alignment="center" valignment="top" leftline="true" width="0pt">
3685 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
3686 <row topline="true" bottomline="true">
3687 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3688 \begin_inset Text
3689
3690 \layout Standard
3691
3692 code
3693 \end_inset 
3694 </cell>
3695 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3696 \begin_inset Text
3697
3698 \layout Standard
3699
3700 Size (bits)
3701 \end_inset 
3702 </cell>
3703 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3704 \begin_inset Text
3705
3706 \layout Standard
3707
3708 Content
3709 \end_inset 
3710 </cell>
3711 </row>
3712 <row topline="true">
3713 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3714 \begin_inset Text
3715
3716 \layout Standard
3717
3718 0
3719 \end_inset 
3720 </cell>
3721 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3722 \begin_inset Text
3723
3724 \layout Standard
3725
3726 1
3727 \end_inset 
3728 </cell>
3729 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3730 \begin_inset Text
3731
3732 \layout Standard
3733
3734 Asks decoder to set perceptual enhancement on (1) or off(1)
3735 \end_inset 
3736 </cell>
3737 </row>
3738 <row topline="true">
3739 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3740 \begin_inset Text
3741
3742 \layout Standard
3743
3744 1
3745 \end_inset 
3746 </cell>
3747 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3748 \begin_inset Text
3749
3750 \layout Standard
3751
3752 1
3753 \end_inset 
3754 </cell>
3755 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3756 \begin_inset Text
3757
3758 \layout Standard
3759
3760 Asks encoder to set VBR on (1) or off(1)
3761 \end_inset 
3762 </cell>
3763 </row>
3764 <row topline="true">
3765 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3766 \begin_inset Text
3767
3768 \layout Standard
3769
3770 2
3771 \end_inset 
3772 </cell>
3773 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3774 \begin_inset Text
3775
3776 \layout Standard
3777
3778 4
3779 \end_inset 
3780 </cell>
3781 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3782 \begin_inset Text
3783
3784 \layout Standard
3785
3786 Asks encoder to switch to mode N
3787 \end_inset 
3788 </cell>
3789 </row>
3790 <row topline="true">
3791 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3792 \begin_inset Text
3793
3794 \layout Standard
3795
3796 3
3797 \end_inset 
3798 </cell>
3799 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3800 \begin_inset Text
3801
3802 \layout Standard
3803
3804 4
3805 \end_inset 
3806 </cell>
3807 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3808 \begin_inset Text
3809
3810 \layout Standard
3811
3812 Asks encoder to switch to mode N for low-band
3813 \end_inset 
3814 </cell>
3815 </row>
3816 <row topline="true">
3817 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3818 \begin_inset Text
3819
3820 \layout Standard
3821
3822 4
3823 \end_inset 
3824 </cell>
3825 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3826 \begin_inset Text
3827
3828 \layout Standard
3829
3830 4
3831 \end_inset 
3832 </cell>
3833 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3834 \begin_inset Text
3835
3836 \layout Standard
3837
3838 Asks encoder to switch to mode N for high-band
3839 \end_inset 
3840 </cell>
3841 </row>
3842 <row topline="true">
3843 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3844 \begin_inset Text
3845
3846 \layout Standard
3847
3848 5
3849 \end_inset 
3850 </cell>
3851 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3852 \begin_inset Text
3853
3854 \layout Standard
3855
3856 4
3857 \end_inset 
3858 </cell>
3859 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3860 \begin_inset Text
3861
3862 \layout Standard
3863
3864 Asks encoder to switch to quality N for VBR
3865 \end_inset 
3866 </cell>
3867 </row>
3868 <row topline="true">
3869 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3870 \begin_inset Text
3871
3872 \layout Standard
3873
3874 6
3875 \end_inset 
3876 </cell>
3877 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3878 \begin_inset Text
3879
3880 \layout Standard
3881
3882 4
3883 \end_inset 
3884 </cell>
3885 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3886 \begin_inset Text
3887
3888 \layout Standard
3889
3890 Request acknowloedge (0=no, 1=all, 2=only for in-band data)
3891 \end_inset 
3892 </cell>
3893 </row>
3894 <row topline="true">
3895 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3896 \begin_inset Text
3897
3898 \layout Standard
3899
3900 7
3901 \end_inset 
3902 </cell>
3903 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3904 \begin_inset Text
3905
3906 \layout Standard
3907
3908 4
3909 \end_inset 
3910 </cell>
3911 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3912 \begin_inset Text
3913
3914 \layout Standard
3915
3916 reserved
3917 \end_inset 
3918 </cell>
3919 </row>
3920 <row topline="true">
3921 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3922 \begin_inset Text
3923
3924 \layout Standard
3925
3926 8
3927 \end_inset 
3928 </cell>
3929 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3930 \begin_inset Text
3931
3932 \layout Standard
3933
3934 8
3935 \end_inset 
3936 </cell>
3937 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3938 \begin_inset Text
3939
3940 \layout Standard
3941
3942 Transmit (8-bit) character to the other end
3943 \end_inset 
3944 </cell>
3945 </row>
3946 <row topline="true">
3947 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3948 \begin_inset Text
3949
3950 \layout Standard
3951
3952 9
3953 \end_inset 
3954 </cell>
3955 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3956 \begin_inset Text
3957
3958 \layout Standard
3959
3960 8
3961 \end_inset 
3962 </cell>
3963 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3964 \begin_inset Text
3965
3966 \layout Standard
3967
3968 Intensity stereo information
3969 \end_inset 
3970 </cell>
3971 </row>
3972 <row topline="true">
3973 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3974 \begin_inset Text
3975
3976 \layout Standard
3977
3978 10
3979 \end_inset 
3980 </cell>
3981 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3982 \begin_inset Text
3983
3984 \layout Standard
3985
3986 16
3987 \end_inset 
3988 </cell>
3989 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3990 \begin_inset Text
3991
3992 \layout Standard
3993
3994 Announce maximum bit-rate acceptable (N in bytes/second)
3995 \end_inset 
3996 </cell>
3997 </row>
3998 <row topline="true">
3999 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4000 \begin_inset Text
4001
4002 \layout Standard
4003
4004 11
4005 \end_inset 
4006 </cell>
4007 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4008 \begin_inset Text
4009
4010 \layout Standard
4011
4012 16
4013 \end_inset 
4014 </cell>
4015 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
4016 \begin_inset Text
4017
4018 \layout Standard
4019
4020 reserved
4021 \end_inset 
4022 </cell>
4023 </row>
4024 <row topline="true">
4025 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4026 \begin_inset Text
4027
4028 \layout Standard
4029
4030 12
4031 \end_inset 
4032 </cell>
4033 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4034 \begin_inset Text
4035
4036 \layout Standard
4037
4038 32
4039 \end_inset 
4040 </cell>
4041 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
4042 \begin_inset Text
4043
4044 \layout Standard
4045
4046 Acknowledge receiving packet N
4047 \end_inset 
4048 </cell>
4049 </row>
4050 <row topline="true">
4051 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4052 \begin_inset Text
4053
4054 \layout Standard
4055
4056 13
4057 \end_inset 
4058 </cell>
4059 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4060 \begin_inset Text
4061
4062 \layout Standard
4063
4064 32
4065 \end_inset 
4066 </cell>
4067 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
4068 \begin_inset Text
4069
4070 \layout Standard
4071
4072 reserved
4073 \end_inset 
4074 </cell>
4075 </row>
4076 <row topline="true">
4077 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4078 \begin_inset Text
4079
4080 \layout Standard
4081
4082 14
4083 \end_inset 
4084 </cell>
4085 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4086 \begin_inset Text
4087
4088 \layout Standard
4089
4090 64
4091 \end_inset 
4092 </cell>
4093 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
4094 \begin_inset Text
4095
4096 \layout Standard
4097
4098 reserved
4099 \end_inset 
4100 </cell>
4101 </row>
4102 <row topline="true" bottomline="true">
4103 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4104 \begin_inset Text
4105
4106 \layout Standard
4107
4108 15
4109 \end_inset 
4110 </cell>
4111 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4112 \begin_inset Text
4113
4114 \layout Standard
4115
4116 64
4117 \end_inset 
4118 </cell>
4119 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
4120 \begin_inset Text
4121
4122 \layout Standard
4123
4124 reserved
4125 \end_inset 
4126 </cell>
4127 </row>
4128 </lyxtabular>
4129
4130 \end_inset 
4131
4132
4133 \layout Caption
4134
4135 In-band signalling codes
4136 \begin_inset LatexCommand \label{cap:In-band-signalling-codes}
4137
4138 \end_inset 
4139
4140
4141 \end_inset 
4142
4143
4144 \layout Standard
4145
4146 Finally, applications may define custom in-band messages using mode 13.
4147  The size of the message in bytes is encoded with 5 bits, so that the decoder
4148  can skip it if it doesn't know how to interpret it.
4149 \layout Section
4150 \pagebreak_top 
4151 Formats and standards
4152 \begin_inset LatexCommand \index{standards}
4153
4154 \end_inset 
4155
4156
4157 \layout Standard
4158
4159 Speex can encode speech in both narrowband and wideband and provides different
4160  bit-rates.
4161  However not all features must be supported by a certain implementation
4162  or device.
4163  In order to be said 
4164 \begin_inset Quotes eld
4165 \end_inset 
4166
4167 Speex compatible
4168 \begin_inset Quotes erd
4169 \end_inset 
4170
4171  (whatever that means), an implementation must implement at least a basic
4172  set of features.
4173 \layout Standard
4174
4175 At the minimum, all narrowband modes of operation MUST be supported at the
4176  decoder.
4177  This includes the decoding of a wideband bit-stream by the narrowband decoder
4178 \begin_inset Foot
4179 collapsed true
4180
4181 \layout Standard
4182
4183 The wideband bit-stream contains an embedded narrowband bit-stream which
4184  can be decoded alone
4185 \end_inset 
4186
4187 .
4188  If present, a wideband decoder MUST be able to decode a narrowband stream,
4189  and MAY either be able to decode all wideband modes or be able to decode
4190  the embedded narrowband part of all modes (which includes ignoring the
4191  high-band bits).
4192 \layout Standard
4193
4194 For encoders, at least one narrowband or wideband mode MUST be supported.
4195  The main reason why all encoding modes do not have to be supported is that
4196  some platforms may not be able to handle the complexity of encoding in
4197  some modes.
4198 \layout Subsection
4199
4200 RTP
4201 \begin_inset LatexCommand \index{RTP}
4202
4203 \end_inset 
4204
4205  Payload Format
4206 \layout Standard
4207
4208 This is a work in progress.
4209 \layout Comment
4210
4211 Since Speex encoded frames already contain mode information, they can be
4212  sent without any other information in an RTP packet.
4213  If more than one frame is transmitted, no byte padding is performed at
4214  the end of frames, except the last one.
4215  The number of frames contained in each packet MUST be transmitted out-of-band.
4216  
4217 \layout Subsection
4218
4219 Ogg
4220 \begin_inset LatexCommand \index{Ogg}
4221
4222 \end_inset 
4223
4224  file format
4225 \layout Standard
4226
4227 Speex bit-streams can be stored in Ogg files.
4228  In this case, the first packet of the Ogg file contains the Speex header
4229  described in table 
4230 \begin_inset LatexCommand \ref{cap:ogg_speex_header}
4231
4232 \end_inset 
4233
4234 .
4235  All integer fields in the headers are stored as little-endian.
4236  The 
4237 \family typewriter 
4238 speex_string
4239 \family default 
4240  field must contain the 
4241 \begin_inset Quotes eld
4242 \end_inset 
4243
4244
4245 \family typewriter 
4246 Speex
4247 \family default 
4248 \SpecialChar ~
4249 \SpecialChar ~
4250 \SpecialChar ~
4251
4252 \begin_inset Quotes eld
4253 \end_inset 
4254
4255  (with 3 training spaces), which identifies the bit-stream.
4256  The next field, 
4257 \family typewriter 
4258 speex_version
4259 \family default 
4260  contains the version of Speex that encoded the file.
4261  For now, refer to speex_header.[ch] for more info.
4262  The 
4263 \emph on 
4264 beginning of stream
4265 \emph default 
4266  (
4267 \family typewriter 
4268 b_o_s
4269 \family default 
4270 ) flag is set to 1 for the header.
4271  The header packet has 
4272 \family typewriter 
4273 packetno=0
4274 \family default 
4275  and 
4276 \family typewriter 
4277 granulepos=0
4278 \family default 
4279 .
4280 \layout Standard
4281
4282 The second packet contains the Speex comment header.
4283  The format used is the Vorbis comment format described here: http://www.xiph.org/
4284 ogg/vorbis/doc/v-comment.html .
4285  This packet has 
4286 \family typewriter 
4287 packetno=1
4288 \family default 
4289  and 
4290 \family typewriter 
4291 granulepos=0
4292 \family default 
4293 .
4294 \layout Standard
4295
4296 The third and subsequant packets each contain one or more (number found
4297  in header) Speex frames.
4298  These are identified with 
4299 \family typewriter 
4300 packetno
4301 \family default 
4302  starting from 2 and the 
4303 \family typewriter 
4304 granulepos
4305 \family default 
4306  is the number of the last sample encoded in that packet.
4307  Le last of these packets has the 
4308 \emph on 
4309 end of stream
4310 \emph default 
4311  (
4312 \family typewriter 
4313 e_o_s
4314 \family default 
4315 ) flag is set to 1.
4316 \layout Standard
4317
4318
4319 \begin_inset Float table
4320 placement htbp
4321 wide true
4322 collapsed false
4323
4324 \layout Standard
4325
4326
4327 \begin_inset  Tabular
4328 <lyxtabular version="3" rows="16" columns="3">
4329 <features>
4330 <column alignment="center" valignment="top" leftline="true" width="0pt">
4331 <column alignment="center" valignment="top" leftline="true" width="0pt">
4332 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
4333 <row topline="true" bottomline="true">
4334 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4335 \begin_inset Text
4336
4337 \layout Standard
4338
4339 Field
4340 \end_inset 
4341 </cell>
4342 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4343 \begin_inset Text
4344
4345 \layout Standard
4346
4347 Type
4348 \end_inset 
4349 </cell>
4350 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
4351 \begin_inset Text
4352
4353 \layout Standard
4354
4355 Size
4356 \end_inset 
4357 </cell>
4358 </row>
4359 <row topline="true">
4360 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4361 \begin_inset Text
4362
4363 \layout Standard
4364
4365 speex_string
4366 \end_inset 
4367 </cell>
4368 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4369 \begin_inset Text
4370
4371 \layout Standard
4372
4373 char[]
4374 \end_inset 
4375 </cell>
4376 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
4377 \begin_inset Text
4378
4379 \layout Standard
4380
4381 8
4382 \end_inset 
4383 </cell>
4384 </row>
4385 <row topline="true">
4386 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4387 \begin_inset Text
4388
4389 \layout Standard
4390
4391 speex_version
4392 \end_inset 
4393 </cell>
4394 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4395 \begin_inset Text
4396
4397 \layout Standard
4398
4399 char[]
4400 \end_inset 
4401 </cell>
4402 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
4403 \begin_inset Text
4404
4405 \layout Standard
4406
4407 20
4408 \end_inset 
4409 </cell>
4410 </row>
4411 <row topline="true">
4412 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4413 \begin_inset Text
4414
4415 \layout Standard
4416
4417 speex_header_version
4418 \end_inset 
4419 </cell>
4420 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4421 \begin_inset Text
4422
4423 \layout Standard
4424
4425 int
4426 \end_inset 
4427 </cell>
4428 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
4429 \begin_inset Text
4430
4431 \layout Standard
4432
4433 4
4434 \end_inset 
4435 </cell>
4436 </row>
4437 <row topline="true">
4438 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4439 \begin_inset Text
4440
4441 \layout Standard
4442
4443 header_size
4444 \end_inset 
4445 </cell>