Updated API-related parts (codec + AEC).
[speexdsp.git] / doc / manual.lyx
1 #LyX 1.4.2 created this file. For more info see http://www.lyx.org/
2 \lyxformat 245
3 \begin_document
4 \begin_header
5 \textclass article
6 \language english
7 \inputencoding auto
8 \fontscheme pslatex
9 \graphics default
10 \paperfontsize default
11 \spacing onehalf
12 \papersize letterpaper
13 \use_geometry false
14 \use_amsmath 1
15 \cite_engine basic
16 \use_bibtopic false
17 \paperorientation portrait
18 \secnumdepth 3
19 \tocdepth 3
20 \paragraph_separation indent
21 \defskip medskip
22 \quotes_language english
23 \papercolumns 1
24 \papersides 1
25 \paperpagestyle headings
26 \tracking_changes false
27 \output_changes true
28 \end_header
29
30 \begin_body
31
32 \begin_layout Title
33 The Speex Codec Manual
34 \newline
35 (version 1.2-beta1)
36 \end_layout
37
38 \begin_layout Author
39 Jean-Marc Valin
40 \end_layout
41
42 \begin_layout Standard
43
44 \newpage
45 Copyright (c) 2002-2005 Jean-Marc Valin/Xiph.org Foundation
46 \end_layout
47
48 \begin_layout Standard
49 Permission is granted to copy, distribute and/or modify this document under
50  the terms of the GNU Free Documentation License, Version 1.1 or any later
51  version published by the Free Software Foundation; with no Invariant Section,
52  with no Front-Cover Texts, and with no Back-Cover.
53  A copy of the license is included in the section entitled "GNU Free Documentati
54 on License".
55  
56 \end_layout
57
58 \begin_layout Standard
59
60 \newpage
61
62 \begin_inset LatexCommand \tableofcontents{}
63
64 \end_inset
65
66
67 \newpage
68
69 \end_layout
70
71 \begin_layout Standard
72 \begin_inset FloatList table
73
74 \end_inset
75
76
77 \newpage
78
79 \end_layout
80
81 \begin_layout Section
82 Introduction to Speex
83 \end_layout
84
85 \begin_layout Standard
86 The Speex project (
87 \family typewriter
88 http://www.speex.org/
89 \family default
90 ) has been started because there was a need for a speech codec that was
91  open-source and free from software patents.
92  These are essential conditions for being used by any open-source software.
93  There is already Vorbis that does general audio, but it is not really suitable
94  for speech.
95  Also, unlike many other speech codecs, Speex is not targeted at cell phones
96  (not many open-source cell phones anyway :-) ) but rather at voice over
97  IP (VoIP) and file-based compression.
98  
99 \end_layout
100
101 \begin_layout Standard
102 As design goals, we wanted to have a codec that would allow both very good
103  quality speech and low bit-rate (unfortunately not at the same time!),
104  which led us to developing a codec with multiple bit-rates.
105  Of course very good quality also meant we had to do wideband (16 kHz sampling
106  rate) in addition to narrowband (telephone quality, 8 kHz sampling rate).
107 \end_layout
108
109 \begin_layout Standard
110 Designing for VoIP instead of cell phone use means that Speex must be robust
111  to lost packets, but not to corrupted ones since packets either arrive
112  unaltered or don't arrive at all.
113  Also, the idea was to have a reasonable complexity and memory requirement
114  without compromising too much on the efficiency of the codec.
115 \end_layout
116
117 \begin_layout Standard
118 All this led us to the choice of CELP
119 \begin_inset LatexCommand \index{CELP}
120
121 \end_inset
122
123  as the encoding technique to use for Speex.
124  One of the main reasons is that CELP has long proved that it could do the
125  job and scale well to both low bit-rates (think DoD CELP @ 4.8 kbps) and
126  high bit-rates (think G.728 @ 16 kbps).
127  
128 \end_layout
129
130 \begin_layout Standard
131 The main characteristics can be summarized as follows:
132 \end_layout
133
134 \begin_layout Itemize
135 Free software/open-source
136 \begin_inset LatexCommand \index{open-source}
137
138 \end_inset
139
140 , patent
141 \begin_inset LatexCommand \index{patent}
142
143 \end_inset
144
145  and royalty-free
146 \end_layout
147
148 \begin_layout Itemize
149 Integration of narrowband
150 \begin_inset LatexCommand \index{narrowband}
151
152 \end_inset
153
154  and wideband
155 \begin_inset LatexCommand \index{wideband}
156
157 \end_inset
158
159  using an embedded bit-stream
160 \end_layout
161
162 \begin_layout Itemize
163 Wide range of bit-rates available (from 2 kbps to 44 kbps)
164 \end_layout
165
166 \begin_layout Itemize
167 Dynamic bit-rate switching and Variable Bit-Rate
168 \begin_inset LatexCommand \index{variable bit-rate}
169
170 \end_inset
171
172  (VBR)
173 \end_layout
174
175 \begin_layout Itemize
176 Voice Activity Detection
177 \begin_inset LatexCommand \index{voice activity detection}
178
179 \end_inset
180
181  (VAD, integrated with VBR)
182 \end_layout
183
184 \begin_layout Itemize
185 Variable complexity
186 \begin_inset LatexCommand \index{complexity}
187
188 \end_inset
189
190
191 \end_layout
192
193 \begin_layout Itemize
194 Ultra-wideband mode at 32 kHz (up to 48 kHz)
195 \end_layout
196
197 \begin_layout Itemize
198 Intensity stereo encoding option
199 \end_layout
200
201 \begin_layout Itemize
202 Fixed-point implementation (work in progress)
203 \end_layout
204
205 \begin_layout Standard
206 This document is divided in the following way.
207  Section 
208 \begin_inset LatexCommand \ref{sec:Feature-description}
209
210 \end_inset
211
212  describes the different Speex features and defines some terms that will
213  be used in later sections.
214  Section 
215 \begin_inset LatexCommand \ref{sec:Command-line-encoder/decoder}
216
217 \end_inset
218
219  provides information about the standard command-line tools, while 
220 \begin_inset LatexCommand \ref{sec:Programming-with-Speex}
221
222 \end_inset
223
224  contains information about programming using the Speex API.
225  Section 
226 \begin_inset LatexCommand \ref{sec:Formats-and-standards}
227
228 \end_inset
229
230  has some information related to Speex and standards.
231  The three last sections describe the internals of the codec and require
232  some signal processing knowledge.
233  Section 
234 \begin_inset LatexCommand \ref{sec:Introduction-to-CELP}
235
236 \end_inset
237
238  explains the general idea behind CELP, while sections 
239 \begin_inset LatexCommand \ref{sec:Speex-narrowband-mode}
240
241 \end_inset
242
243  and 
244 \begin_inset LatexCommand \ref{sec:Speex-wideband-mode}
245
246 \end_inset
247
248  are specific to Speex.
249  Note that if you are only interested in using Speex, those three last sections
250  are not required.
251 \end_layout
252
253 \begin_layout Standard
254
255 \newpage
256
257 \end_layout
258
259 \begin_layout Section
260 Codec description
261 \begin_inset LatexCommand \label{sec:Feature-description}
262
263 \end_inset
264
265
266 \end_layout
267
268 \begin_layout Standard
269 This section describes the main features provided by Speex.
270 \end_layout
271
272 \begin_layout Subsection
273 Concepts
274 \end_layout
275
276 \begin_layout Standard
277 Here are some concepts in speech coding that help better understand the
278  rest of the manual.
279  Emphasis is placed on the Speex features.
280 \end_layout
281
282 \begin_layout Subsection*
283 Sampling rate
284 \begin_inset LatexCommand \index{sampling rate}
285
286 \end_inset
287
288
289 \end_layout
290
291 \begin_layout Standard
292 Speex is mainly designed for 3 different sampling rates: 8 kHz, 16 kHz,
293  and 32 kHz.
294  These are respectively refered to as narrowband
295 \begin_inset LatexCommand \index{narrowband}
296
297 \end_inset
298
299 , wideband
300 \begin_inset LatexCommand \index{wideband}
301
302 \end_inset
303
304  and ultra-wideband
305 \begin_inset LatexCommand \index{ultra-wideband}
306
307 \end_inset
308
309 .
310  
311 \end_layout
312
313 \begin_layout Subsection*
314 Quality
315 \begin_inset LatexCommand \index{quality}
316
317 \end_inset
318
319
320 \end_layout
321
322 \begin_layout Standard
323 Speex encoding is controlled most of the time by a quality parameter that
324  ranges from 0 to 10.
325  In constant bit-rate
326 \begin_inset LatexCommand \index{constant bit-rate}
327
328 \end_inset
329
330  (CBR) operation, the quality parameter is an integer, while for variable
331  bit-rate (VBR), the parameter is a float.
332  
333 \end_layout
334
335 \begin_layout Subsection*
336 Complexity
337 \begin_inset LatexCommand \index{complexity}
338
339 \end_inset
340
341  (variable)
342 \end_layout
343
344 \begin_layout Standard
345 With Speex, it is possible to vary the complexity allowed for the encoder.
346  This is done by controlling how the search is performed with an integer
347  ranging from 1 to 10 in a way that's similar to the -1 to -9 options to
348  
349 \emph on
350 gzip
351 \emph default
352  and 
353 \emph on
354 bzip2
355 \emph default
356  compression utilities.
357  For normal use, the noise level at complexity 1 is between 1 and 2 dB higher
358  than at complexity 10, but the CPU requirements for complexity 10 is about
359  5 times higher than for complexity 1.
360  In practice, the best trade-off is between complexity 2 and 4, though higher
361  settings are often useful when encoding non-speech sounds like DTMF
362 \begin_inset LatexCommand \index{DTMF}
363
364 \end_inset
365
366  tones.
367 \end_layout
368
369 \begin_layout Subsection*
370 Variable Bit-Rate
371 \begin_inset LatexCommand \index{variable bit-rate}
372
373 \end_inset
374
375  (VBR)
376 \end_layout
377
378 \begin_layout Standard
379 Variable bit-rate (VBR) allows a codec to change its bit-rate dynamically
380  to adapt to the 
381 \begin_inset Quotes eld
382 \end_inset
383
384 difficulty
385 \begin_inset Quotes erd
386 \end_inset
387
388  of the audio being encoded.
389  In the example of Speex, sounds like vowels and high-energy transients
390  require a higher bit-rate to achieve good quality, while fricatives (e.g.
391  s,f sounds) can be coded adequately with less bits.
392  For this reason, VBR can achive lower bit-rate for the same quality, or
393  a better quality for a certain bit-rate.
394  Despite its advantages, VBR has two main drawbacks: first, by only specifying
395  quality, there's no guaranty about the final average bit-rate.
396  Second, for some real-time applications like voice over IP (VoIP), what
397  counts is the maximum bit-rate, which must be low enough for the communication
398  channel.
399 \end_layout
400
401 \begin_layout Subsection*
402 Average Bit-Rate
403 \begin_inset LatexCommand \index{average bit-rate}
404
405 \end_inset
406
407  (ABR)
408 \end_layout
409
410 \begin_layout Standard
411 Average bit-rate solves one of the problems of VBR, as it dynamically adjusts
412  VBR quality in order to meet a specific target bit-rate.
413  Because the quality/bit-rate is adjusted in real-time (open-loop), the
414  global quality will be slightly lower than that obtained by encoding in
415  VBR with exactly the right quality setting to meet the target average bit-rate.
416 \end_layout
417
418 \begin_layout Subsection*
419 Voice Activity Detection
420 \begin_inset LatexCommand \index{voice activity detection}
421
422 \end_inset
423
424  (VAD)
425 \end_layout
426
427 \begin_layout Standard
428 When enabled, voice activity detection detects whether the audio being encoded
429  is speech or silence/background noise.
430  VAD is always implicitly activated when encoding in VBR, so the option
431  is only useful in non-VBR operation.
432  In this case, Speex detects non-speech periods and encode them with just
433  enough bits to reproduce the background noise.
434  This is called 
435 \begin_inset Quotes eld
436 \end_inset
437
438 comfort noise generation
439 \begin_inset Quotes erd
440 \end_inset
441
442  (CNG).
443 \end_layout
444
445 \begin_layout Subsection*
446 Discontinuous Transmission
447 \begin_inset LatexCommand \index{discontinuous transmission}
448
449 \end_inset
450
451  (DTX)
452 \end_layout
453
454 \begin_layout Standard
455 Discontinuous transmission is an addition to VAD/VBR operation, that allows
456  to stop transmitting completely when the background noise is stationary.
457  In file-based operation, since we cannot just stop writing to the file,
458  only 5 bits are used for such frames (corresponding to 250 bps).
459 \end_layout
460
461 \begin_layout Subsection*
462 Perceptual enhancement
463 \begin_inset LatexCommand \index{perceptual enhancement}
464
465 \end_inset
466
467
468 \end_layout
469
470 \begin_layout Standard
471 Perceptual enhancement is a part of the decoder which, when turned on, tries
472  to reduce (the perception of) the noise produced by the coding/decoding
473  process.
474  In most cases, perceptual enhancement make the sound further from the original
475  
476 \emph on
477 objectively
478 \emph default
479  (if you use SNR), but in the end it still 
480 \emph on
481 sounds
482 \emph default
483  better (subjective improvement).
484 \end_layout
485
486 \begin_layout Subsection*
487 Algorithmic delay
488 \begin_inset LatexCommand \index{algorithmic delay}
489
490 \end_inset
491
492
493 \end_layout
494
495 \begin_layout Standard
496 Every speech codec introduces a delay in the transmission.
497  For Speex, this delay is equal to the frame size, plus some amount of 
498 \begin_inset Quotes eld
499 \end_inset
500
501 look-ahead
502 \begin_inset Quotes erd
503 \end_inset
504
505  required to process each frame.
506  In narrowband operation (8 kHz), the delay is 30 ms, while for wideband
507  (16 kHz), the delay is 34 ms.
508  These values don't account for the CPU time it takes to encode or decode
509  the frames.
510 \end_layout
511
512 \begin_layout Subsection
513 Codec
514 \end_layout
515
516 \begin_layout Subsection
517 Preprocessor
518 \end_layout
519
520 \begin_layout Standard
521 This part refers to the preprocessor module introduced in the 1.1.x branch.
522  The preprocessor is designed to be used on the audio 
523 \emph on
524 before
525 \emph default
526  running the encoder.
527  The preprocessor provides three main functionalities:
528 \end_layout
529
530 \begin_layout Itemize
531 denoising
532 \end_layout
533
534 \begin_layout Itemize
535 automatic gain control (AGC)
536 \end_layout
537
538 \begin_layout Itemize
539 voice activity detection (VAD)
540 \end_layout
541
542 \begin_layout Standard
543 The denoiser can be used to reduce the amount of background noise present
544  in the input signal.
545  This provides higher quality speech whether or not the denoised signal
546  is encoded with Speex (or at all).
547  However, when using the denoised signal with the codec, there is an additional
548  benefit.
549  Speech codecs in general (Speex included) tend to perform poorly on noisy
550  input, which tends to amplify the noise.
551  The denoiser greatly reduces this effect.
552 \end_layout
553
554 \begin_layout Standard
555 Automatic gain control (AGC) is a feature that deals with the fact that
556  the recording volume may vary by a large amount between different setups.
557  The AGC provides a way to adjust a signal to a reference volume.
558  This is useful for voice over IP because it removes the need for manual
559  adjustment of the microphone gain.
560  A secondary advantage is that by setting the microphone gain to a conservative
561  (low) level, it is easier to avoid clipping.
562 \end_layout
563
564 \begin_layout Standard
565 The voice activity detector (VAD) provided by the preprocessor is more advanced
566  than the one directly provided in the codec.
567  
568 \end_layout
569
570 \begin_layout Subsection
571 Adaptive Jitter Buffer
572 \end_layout
573
574 \begin_layout Subsection
575 Acoustic Echo Canceller
576 \end_layout
577
578 \begin_layout Standard
579
580 \newpage
581
582 \end_layout
583
584 \begin_layout Section
585 Compiling
586 \end_layout
587
588 \begin_layout Standard
589 Compiling Speex under UNIX or any platform supported by autoconf (e.g.
590  Win32/cygwin) is as easy as typing:
591 \end_layout
592
593 \begin_layout LyX-Code
594 % ./configure [options]
595 \end_layout
596
597 \begin_layout LyX-Code
598 % make
599 \end_layout
600
601 \begin_layout LyX-Code
602 % make install
603 \end_layout
604
605 \begin_layout Standard
606 The options supported by the Speex configure script are:
607 \end_layout
608
609 \begin_layout Description
610 --prefix=<path> Specifies where to install Speex
611 \end_layout
612
613 \begin_layout Description
614 --enable-shared/--disable-shared Whether to compile shared libraries
615 \end_layout
616
617 \begin_layout Description
618 --enable-static/--disable-static Whether to compile static libraries
619 \end_layout
620
621 \begin_layout Description
622 --disable-wideband Disable the wideband part of Speex (typically to same
623  space)
624 \end_layout
625
626 \begin_layout Description
627 --enable-valgrind Enable extra information when (and only when) running
628  with valgrind
629 \end_layout
630
631 \begin_layout Description
632 --enable-sse Enable use of SSE instructions (x86/float only)
633 \end_layout
634
635 \begin_layout Description
636 --enable-fixed-point
637 \begin_inset LatexCommand \index{fixed-point}
638
639 \end_inset
640
641  Compile Speex for a processor that does not have a floating point unit
642  (FPU)
643 \end_layout
644
645 \begin_layout Description
646 --enable-arm4-asm Enable assembly specific to the ARMv4 architecture (gcc
647  only)
648 \end_layout
649
650 \begin_layout Description
651 --enable-arm5e-asm Enable assembly specific to the ARMv5E architecture (gcc
652  only)
653 \end_layout
654
655 \begin_layout Description
656 --enable-fixed-point-debug Use only for debugging the fixed-point
657 \begin_inset LatexCommand \index{fixed-point}
658
659 \end_inset
660
661  code (very slow)
662 \end_layout
663
664 \begin_layout Description
665 --enable-epic-48k Enable a special (and non-compatible) 4.8 kbps narrowband
666  mode
667 \end_layout
668
669 \begin_layout Description
670 --enable-ti-c55x Enable support for the TI C5x family
671 \end_layout
672
673 \begin_layout Description
674 --enable-blackfin-asm Enable assembly specific to the Blackfin DSP architecture
675  (gcc only)
676 \end_layout
677
678 \begin_layout Description
679 --enable-16bit-precision Reduces precision to 16 bits in time-critical areas
680  (fixed-point only)
681 \end_layout
682
683 \begin_layout Standard
684
685 \newpage
686
687 \end_layout
688
689 \begin_layout Section
690 Command-line encoder/decoder
691 \begin_inset LatexCommand \label{sec:Command-line-encoder/decoder}
692
693 \end_inset
694
695
696 \end_layout
697
698 \begin_layout Standard
699 The base Speex distribution includes a command-line encoder (
700 \emph on
701 speexenc
702 \emph default
703 ) and decoder (
704 \emph on
705 speexdec
706 \emph default
707 ).
708  This section describes how to use these tools.
709 \end_layout
710
711 \begin_layout Subsection
712
713 \emph on
714 speexenc
715 \begin_inset LatexCommand \index{speexenc}
716
717 \end_inset
718
719
720 \end_layout
721
722 \begin_layout Standard
723 The 
724 \emph on
725 speexenc
726 \emph default
727  utility is used to create Speex files from raw PCM or wave files.
728  It can be used by calling: 
729 \end_layout
730
731 \begin_layout LyX-Code
732 speexenc [options] input_file output_file
733 \end_layout
734
735 \begin_layout Standard
736 The value '-' for input_file or output_file corresponds respectively to
737  stdin and stdout.
738  The valid options are:
739 \end_layout
740
741 \begin_layout Description
742 --narrowband\InsetSpace ~
743 (-n) Tell Speex to treat the input as narrowband (8 kHz).
744  This is the default
745 \end_layout
746
747 \begin_layout Description
748 --wideband\InsetSpace ~
749 (-w) Tell Speex to treat the input as wideband (16 kHz)
750 \end_layout
751
752 \begin_layout Description
753 --ultra-wideband\InsetSpace ~
754 (-u) Tell Speex to treat the input as 
755 \begin_inset Quotes eld
756 \end_inset
757
758 ultra-wideband
759 \begin_inset Quotes erd
760 \end_inset
761
762  (32 kHz)
763 \end_layout
764
765 \begin_layout Description
766 --quality\InsetSpace ~
767 n Set the encoding quality (0-10), default is 8
768 \end_layout
769
770 \begin_layout Description
771 --bitrate\InsetSpace ~
772 n Encoding bit-rate (use bit-rate n or lower) 
773 \end_layout
774
775 \begin_layout Description
776 --vbr Enable VBR (Variable Bit-Rate), disabled by default
777 \end_layout
778
779 \begin_layout Description
780 --abr\InsetSpace ~
781 n Enable ABR (Average Bit-Rate) at n kbps, disabled by default
782 \end_layout
783
784 \begin_layout Description
785 --vad Enable VAD (Voice Activity Detection), disabled by default
786 \end_layout
787
788 \begin_layout Description
789 --dtx Enable DTX (Discontinuous Transmission), disabled by default
790 \end_layout
791
792 \begin_layout Description
793 --nframes\InsetSpace ~
794 n Pack n frames in each Ogg packet (this saves space at low bit-rates)
795 \end_layout
796
797 \begin_layout Description
798 --comp\InsetSpace ~
799 n Set encoding speed/quality tradeoff.
800  The higher the value of n, the slower the encoding (default is 3)
801 \end_layout
802
803 \begin_layout Description
804 -V Verbose operation, print bit-rate currently in use
805 \end_layout
806
807 \begin_layout Description
808 --help\InsetSpace ~
809 (-h) Print the help
810 \end_layout
811
812 \begin_layout Description
813 --version\InsetSpace ~
814 (-v) Print version information
815 \end_layout
816
817 \begin_layout Subsubsection*
818 Speex comments
819 \end_layout
820
821 \begin_layout Description
822 --comment Add the given string as an extra comment.
823  This may be used multiple times.
824  
825 \end_layout
826
827 \begin_layout Description
828 --author Author of this track.
829  
830 \end_layout
831
832 \begin_layout Description
833 --title Title for this track.
834  
835 \end_layout
836
837 \begin_layout Subsubsection*
838 Raw input options
839 \end_layout
840
841 \begin_layout Description
842 --rate\InsetSpace ~
843 n Sampling rate for raw input
844 \end_layout
845
846 \begin_layout Description
847 --stereo Consider raw input as stereo 
848 \end_layout
849
850 \begin_layout Description
851 --le Raw input is little-endian 
852 \end_layout
853
854 \begin_layout Description
855 --be Raw input is big-endian 
856 \end_layout
857
858 \begin_layout Description
859 --8bit Raw input is 8-bit unsigned 
860 \end_layout
861
862 \begin_layout Description
863 --16bit Raw input is 16-bit signed 
864 \end_layout
865
866 \begin_layout Subsection
867
868 \emph on
869 speexdec
870 \begin_inset LatexCommand \index{speexdec}
871
872 \end_inset
873
874
875 \end_layout
876
877 \begin_layout Standard
878 The 
879 \emph on
880 speexdec
881 \emph default
882  utility is used to decode Speex files and can be used by calling: 
883 \end_layout
884
885 \begin_layout LyX-Code
886 speexdec [options] speex_file [output_file]
887 \end_layout
888
889 \begin_layout Standard
890 The value '-' for input_file or output_file corresponds respectively to
891  stdin and stdout.
892  Also, when no output_file is specified, the file is played to the soundcard.
893  The valid options are:
894 \end_layout
895
896 \begin_layout Description
897 --enh enable post-filter (default)
898 \end_layout
899
900 \begin_layout Description
901 --no-enh disable post-filter
902 \end_layout
903
904 \begin_layout Description
905 --force-nb Force decoding in narrowband 
906 \end_layout
907
908 \begin_layout Description
909 --force-wb Force decoding in wideband 
910 \end_layout
911
912 \begin_layout Description
913 --force-uwb Force decoding in ultra-wideband 
914 \end_layout
915
916 \begin_layout Description
917 --mono Force decoding in mono 
918 \end_layout
919
920 \begin_layout Description
921 --stereo Force decoding in stereo 
922 \end_layout
923
924 \begin_layout Description
925 --rate\InsetSpace ~
926 n Force decoding at n Hz sampling rate
927 \end_layout
928
929 \begin_layout Description
930 --packet-loss\InsetSpace ~
931 n Simulate n % random packet loss
932 \end_layout
933
934 \begin_layout Description
935 -V Verbose operation, print bit-rate currently in use
936 \end_layout
937
938 \begin_layout Description
939 --help\InsetSpace ~
940 (-h) Print the help
941 \end_layout
942
943 \begin_layout Description
944 --version\InsetSpace ~
945 (-v) Print version information
946 \end_layout
947
948 \begin_layout Standard
949
950 \newpage
951
952 \end_layout
953
954 \begin_layout Section
955 Programming with Speex (the libspeex
956 \begin_inset LatexCommand \index{libspeex}
957
958 \end_inset
959
960  API
961 \begin_inset LatexCommand \index{API}
962
963 \end_inset
964
965 )
966 \begin_inset LatexCommand \label{sec:Programming-with-Speex}
967
968 \end_inset
969
970
971 \end_layout
972
973 \begin_layout Standard
974 This section explains how to use the Speex API.
975  Examples of code can also be found in appendix 
976 \begin_inset LatexCommand \ref{sec:Sample-code}
977
978 \end_inset
979
980 .
981 \end_layout
982
983 \begin_layout Subsection
984 Encoding
985 \begin_inset LatexCommand \label{sub:Encoding}
986
987 \end_inset
988
989
990 \end_layout
991
992 \begin_layout Standard
993 In order to encode speech using Speex, you first need to:
994 \end_layout
995
996 \begin_layout LyX-Code
997 #include <speex/speex.h>
998 \end_layout
999
1000 \begin_layout Standard
1001 You then need to declare a Speex bit-packing struct
1002 \end_layout
1003
1004 \begin_layout LyX-Code
1005 SpeexBits bits;
1006 \end_layout
1007
1008 \begin_layout Standard
1009 and a Speex encoder state
1010 \end_layout
1011
1012 \begin_layout LyX-Code
1013 void *enc_state;
1014 \end_layout
1015
1016 \begin_layout Standard
1017 The two are initialized by:
1018 \end_layout
1019
1020 \begin_layout LyX-Code
1021 speex_bits_init(&bits);
1022 \end_layout
1023
1024 \begin_layout LyX-Code
1025 enc_state = speex_encoder_init(&speex_nb_mode);
1026 \end_layout
1027
1028 \begin_layout Standard
1029 For wideband coding, 
1030 \emph on
1031 speex_nb_mode
1032 \emph default
1033  will be replaced by 
1034 \emph on
1035 speex_wb_mode
1036 \emph default
1037 .
1038  In most cases, you will need to know the frame size used by the mode you
1039  are using.
1040  You can get that value in the 
1041 \emph on
1042 frame_size
1043 \emph default
1044  variable with:
1045 \end_layout
1046
1047 \begin_layout LyX-Code
1048 speex_encoder_ctl(enc_state,SPEEX_GET_FRAME_SIZE,&frame_size);
1049 \end_layout
1050
1051 \begin_layout Standard
1052 In practice, 
1053 \emph on
1054 frame_size
1055 \emph default
1056  will correspond to 20 ms when using 8, 16, or 32 kHz sampling rate.
1057 \end_layout
1058
1059 \begin_layout Standard
1060 Once the initialization is done, for every input frame:
1061 \end_layout
1062
1063 \begin_layout LyX-Code
1064 speex_bits_reset(&bits);
1065 \end_layout
1066
1067 \begin_layout LyX-Code
1068 speex_encode_int(enc_state, input_frame, &bits);
1069 \end_layout
1070
1071 \begin_layout LyX-Code
1072 nbBytes = speex_bits_write(&bits, byte_ptr, MAX_NB_BYTES);
1073 \end_layout
1074
1075 \begin_layout Standard
1076 where 
1077 \emph on
1078 input_frame
1079 \emph default
1080  is a 
1081 \emph on
1082 (
1083 \emph default
1084 short
1085 \emph on
1086  *)
1087 \emph default
1088  pointing to the beginning of a speech frame, 
1089 \emph on
1090 byte_ptr
1091 \emph default
1092  is a 
1093 \emph on
1094 (char *)
1095 \emph default
1096  where the encoded frame will be written, 
1097 \emph on
1098 MAX_NB_BYTES
1099 \emph default
1100  is the maximum number of bytes that can be written to 
1101 \emph on
1102 byte_ptr
1103 \emph default
1104  without causing an overflow and 
1105 \emph on
1106 nbBytes
1107 \emph default
1108  is the number of bytes actually written to 
1109 \emph on
1110 byte_ptr
1111 \emph default
1112  (the encoded size in bytes).
1113  Before calling speex_bits_write, it is possible to find the number of bytes
1114  that need to be written by calling 
1115 \family typewriter
1116 speex_bits_nbytes(&bits)
1117 \family default
1118 , which returns a number of bytes.
1119 \end_layout
1120
1121 \begin_layout Standard
1122 It is still possible to use the 
1123 \emph on
1124 speex_encode()
1125 \emph default
1126  function, which takes a 
1127 \emph on
1128 (float *)
1129 \emph default
1130  for the audio.
1131  However, this would make an eventual port to an FPU-less platform (like
1132  ARM) more complicated.
1133  Internally, 
1134 \emph on
1135 speex_encode() 
1136 \emph default
1137 and
1138 \emph on
1139  speex_encode_int()
1140 \emph default
1141  are processed in the same way.
1142  Whether the encoder uses the fixed-point version is only decided by the
1143  compile-time flags, not at the API level.
1144 \end_layout
1145
1146 \begin_layout Standard
1147 After you're done with the encoding, free all resources with:
1148 \end_layout
1149
1150 \begin_layout LyX-Code
1151 speex_bits_destroy(&bits);
1152 \end_layout
1153
1154 \begin_layout LyX-Code
1155 speex_encoder_destroy(enc_state);
1156 \end_layout
1157
1158 \begin_layout Standard
1159 That's about it for the encoder.
1160  
1161 \end_layout
1162
1163 \begin_layout Subsection
1164 Decoding
1165 \begin_inset LatexCommand \label{sub:Decoding}
1166
1167 \end_inset
1168
1169
1170 \end_layout
1171
1172 \begin_layout Standard
1173 In order to decode speech using Speex, you first need to:
1174 \end_layout
1175
1176 \begin_layout LyX-Code
1177 #include <speex/speex.h>
1178 \end_layout
1179
1180 \begin_layout Standard
1181 You also need to declare a Speex bit-packing struct
1182 \end_layout
1183
1184 \begin_layout LyX-Code
1185 SpeexBits bits;
1186 \end_layout
1187
1188 \begin_layout Standard
1189 and a Speex decoder state
1190 \end_layout
1191
1192 \begin_layout LyX-Code
1193 void *dec_state;
1194 \end_layout
1195
1196 \begin_layout Standard
1197 The two are initialized by:
1198 \end_layout
1199
1200 \begin_layout LyX-Code
1201 speex_bits_init(&bits);
1202 \end_layout
1203
1204 \begin_layout LyX-Code
1205 dec_state = speex_decoder_init(&speex_nb_mode);
1206 \end_layout
1207
1208 \begin_layout Standard
1209 For wideband decoding, 
1210 \emph on
1211 speex_nb_mode
1212 \emph default
1213  will be replaced by 
1214 \emph on
1215 speex_wb_mode
1216 \emph default
1217 .
1218  If you need to obtain the size of the frames that will be used by the decoder,
1219  you can get that value in the 
1220 \emph on
1221 frame_size
1222 \emph default
1223  variable with:
1224 \end_layout
1225
1226 \begin_layout LyX-Code
1227 speex_decoder_ctl(dec_state, SPEEX_GET_FRAME_SIZE, &frame_size); 
1228 \end_layout
1229
1230 \begin_layout Standard
1231 There is also a parameter that can be set for the decoder: whether or not
1232  to use a perceptual enhancer.
1233  This can be set by: 
1234 \end_layout
1235
1236 \begin_layout LyX-Code
1237 speex_decoder_ctl(dec_state, SPEEX_SET_ENH, &enh); 
1238 \end_layout
1239
1240 \begin_layout Standard
1241 where 
1242 \emph on
1243 enh
1244 \emph default
1245  is an int with value 0 to have the enhancer disabled and 1 to have it enabled.
1246  As of 1.2-beta1, the default is now to enable the enhancer.
1247 \end_layout
1248
1249 \begin_layout Standard
1250 Again, once the decoder initialization is done, for every input frame:
1251 \end_layout
1252
1253 \begin_layout LyX-Code
1254 speex_bits_read_from(&bits, input_bytes, nbBytes);
1255 \end_layout
1256
1257 \begin_layout LyX-Code
1258 speex_decode_int(dec_state, &bits, output_frame);
1259 \end_layout
1260
1261 \begin_layout Standard
1262 where input_bytes is a 
1263 \emph on
1264 (char *)
1265 \emph default
1266  containing the bit-stream data received for a frame, 
1267 \emph on
1268 nbBytes
1269 \emph default
1270  is the size (in bytes) of that bit-stream, and 
1271 \emph on
1272 output_frame
1273 \emph default
1274  is a 
1275 \emph on
1276 (short *)
1277 \emph default
1278  and points to the area where the decoded speech frame will be written.
1279  A NULL value as the first argument indicates that we don't have the bits
1280  for the current frame.
1281  When a frame is lost, the Speex decoder will do its best to "guess" the
1282  correct signal.
1283 \end_layout
1284
1285 \begin_layout Standard
1286 As for the encoder, the 
1287 \emph on
1288 speex_decode()
1289 \emph default
1290  function can still be used, with a 
1291 \emph on
1292 (float *)
1293 \emph default
1294  as the output for the audio.
1295 \end_layout
1296
1297 \begin_layout Standard
1298 After you're done with the decoding, free all resources with:
1299 \end_layout
1300
1301 \begin_layout LyX-Code
1302 speex_bits_destroy(&bits);
1303 \end_layout
1304
1305 \begin_layout LyX-Code
1306 speex_decoder_destroy(dec_state);
1307 \end_layout
1308
1309 \begin_layout Subsection
1310 Preprocessor
1311 \begin_inset LatexCommand \label{sub:Preprocessor}
1312
1313 \end_inset
1314
1315
1316 \end_layout
1317
1318 \begin_layout Standard
1319 In order to use the Speex preprocessor
1320 \begin_inset LatexCommand \index{preprocessor}
1321
1322 \end_inset
1323
1324 , you first need to:
1325 \end_layout
1326
1327 \begin_layout LyX-Code
1328 #include <speex/speex_preprocess.h>
1329 \end_layout
1330
1331 \begin_layout Standard
1332 Then, a preprocessor state can be created as:
1333 \end_layout
1334
1335 \begin_layout LyX-Code
1336 SpeexPreprocessState *preprocess_state = speex_preprocess_state_init(frame_size,
1337  sampling_rate);
1338 \end_layout
1339
1340 \begin_layout Standard
1341 It is recommended to use the same value for 
1342 \family typewriter
1343 frame_size
1344 \family default
1345  as is used by the encoder (20 
1346 \emph on
1347 ms
1348 \emph default
1349 ).
1350 \end_layout
1351
1352 \begin_layout Standard
1353 For each input frame, you need to call:
1354 \end_layout
1355
1356 \begin_layout LyX-Code
1357 speex_preprocess(preprocess_state, audio_frame, echo_residue);
1358 \end_layout
1359
1360 \begin_layout Standard
1361 where 
1362 \family typewriter
1363 audio_frame
1364 \family default
1365  is used both as input and output and 
1366 \family typewriter
1367 echo_residue
1368 \family default
1369  is either an array filled by the echo canceller, or NULL if the preprocessor
1370  is used without the echo canceller.
1371 \end_layout
1372
1373 \begin_layout Standard
1374 In cases where the output audio is not useful for a certain frame, it is
1375  possible to use instead:
1376 \end_layout
1377
1378 \begin_layout LyX-Code
1379 speex_preprocess_estimate_update(preprocess_state, audio_frame, echo_residue);
1380 \end_layout
1381
1382 \begin_layout Standard
1383 This call will update all the preprocessor internal state variables without
1384  computing the output audio, thus saving some CPU cycles.
1385 \end_layout
1386
1387 \begin_layout Standard
1388 The behaviour of the preprocessor can be changed using:
1389 \end_layout
1390
1391 \begin_layout LyX-Code
1392 speex_preprocess_ctl(preprocess_state, request, ptr);
1393 \end_layout
1394
1395 \begin_layout Standard
1396 which is used in the same way as the encoder and decoder equivalent.
1397  Options are listed in Section .
1398 \end_layout
1399
1400 \begin_layout Standard
1401 The preprocessor state can be destroyed using:
1402 \end_layout
1403
1404 \begin_layout LyX-Code
1405 speex_preprocess_state_destroy(preprocess_state);
1406 \end_layout
1407
1408 \begin_layout Subsection
1409 Echo Cancellation
1410 \begin_inset LatexCommand \label{sub:Echo-Cancellation}
1411
1412 \end_inset
1413
1414
1415 \end_layout
1416
1417 \begin_layout Standard
1418 The Speex library now includes an echo cancellation
1419 \begin_inset LatexCommand \index{echo cancellation}
1420
1421 \end_inset
1422
1423  algorithm suitable for Acoustic Echo Cancellation
1424 \begin_inset LatexCommand \index{acoustic echo cancellation}
1425
1426 \end_inset
1427
1428  (AEC).
1429  In order to use the echo canceller, you first need to
1430 \end_layout
1431
1432 \begin_layout LyX-Code
1433 #include <speex/speex_echo.h>
1434 \end_layout
1435
1436 \begin_layout Standard
1437 Then, an echo canceller state can be created by:
1438 \end_layout
1439
1440 \begin_layout LyX-Code
1441 SpeexEchoState *echo_state = speex_echo_state_init(frame_size, filter_length);
1442 \end_layout
1443
1444 \begin_layout Standard
1445 where 
1446 \family typewriter
1447 frame_size
1448 \family default
1449  is the amount of data (in samples) you want to process at once and 
1450 \family typewriter
1451 filter_length
1452 \family default
1453  is the length (in samples) of the echo cancelling filter you want to use
1454  (also known as 
1455 \shape italic
1456 tail length
1457 \shape default
1458
1459 \begin_inset LatexCommand \index{tail length}
1460
1461 \end_inset
1462
1463 ).
1464  It is recommended to use a frame size in the order of 20 ms (or equal to
1465  the codec frame size) and make sure it is easy to perform an FFT of that
1466  size (powers of two are better than prime sizes).
1467  The recommended tail length is approximately the third of the room reverberatio
1468 n time.
1469  For example, in a small room, reverberation time is in the order of 300
1470  ms, so a tail length of 100 ms is a good choice (800 samples at 8000 Hz
1471  sampling rate).
1472 \end_layout
1473
1474 \begin_layout Standard
1475 Once the echo canceller state is created, audio can be processed by:
1476 \end_layout
1477
1478 \begin_layout LyX-Code
1479 speex_echo_cancel(echo_state, input_frame, echo_frame, output_frame, residue);
1480 \end_layout
1481
1482 \begin_layout Standard
1483 where 
1484 \family typewriter
1485 input_frame
1486 \family default
1487  is the audio as captured by the microphone, 
1488 \family typewriter
1489 echo_frame
1490 \family default
1491  is the signal that was played in the speaker (and needs to be removed)
1492  and 
1493 \family typewriter
1494 output_frame
1495 \family default
1496  is the signal with echo removed.
1497  The 
1498 \family typewriter
1499 residue
1500 \family default
1501  parameter is optional (you can set it to NULL) and is used to return the
1502  estimated power spectrum of the echo residue so it can be removed by the
1503  preprocessor (if you with to use it).
1504  
1505 \end_layout
1506
1507 \begin_layout Standard
1508 One important thing to keep in mind is the relationship between 
1509 \family typewriter
1510 input_frame
1511 \family default
1512  and 
1513 \family typewriter
1514 echo_frame
1515 \family default
1516 .
1517  It is important that, at any time, any echo that is present in the input
1518  has already been sent to the echo canceller as 
1519 \family typewriter
1520 echo_frame
1521 \family default
1522 .
1523  In other words, the echo canceller cannot remove a signal that it hasn't
1524  yet received.
1525  On the other hand, the delay between the input signal and the echo signal
1526  must be small enough because otherwise part of the echo cancellation filter
1527  is inefficient.
1528  In the ideal case, you code would look like:
1529 \end_layout
1530
1531 \begin_layout LyX-Code
1532 write_to_soundcard(echo_frame, frame_size);
1533 \end_layout
1534
1535 \begin_layout LyX-Code
1536 read_from_soundcard(input_frame, frame_size);
1537 \end_layout
1538
1539 \begin_layout LyX-Code
1540 speex_echo_cancel(echo_state, input_frame, echo_frame, output_frame, residue);
1541 \end_layout
1542
1543 \begin_layout Standard
1544 As stated above, if you wish to further reduce the echo present in the signal,
1545  you can do so by passing 
1546 \family typewriter
1547 residue
1548 \family default
1549  as the last parameter of 
1550 \family typewriter
1551 speex_preprocess()
1552 \family default
1553  function (see Section 
1554 \begin_inset LatexCommand \ref{sub:Preprocessor}
1555
1556 \end_inset
1557
1558 ).
1559 \end_layout
1560
1561 \begin_layout Standard
1562 As of version 1.2-beta1, there is an alternative, simpler API that can be
1563  used instead of 
1564 \emph on
1565 speex_echo_cancel()
1566 \emph default
1567 .
1568  When audio capture and playback are handled asynchronously (e.g.
1569  in different threads or using the 
1570 \emph on
1571 poll()
1572 \emph default
1573  or 
1574 \emph on
1575 select()
1576 \emph default
1577  system call), it can be difficult to keep track of what input_frame comes
1578  with what echo_frame.
1579  Instead, the playback comtext/thread can simply call:
1580 \end_layout
1581
1582 \begin_layout LyX-Code
1583 speex_echo_playback(echo_state, echo_frame);
1584 \end_layout
1585
1586 \begin_layout Standard
1587 every time an audio frame is played.
1588  Then, the capture context/thread calls:
1589 \end_layout
1590
1591 \begin_layout LyX-Code
1592 speex_echo_capture(echo_state, input_frame, output_frame, residue);
1593 \end_layout
1594
1595 \begin_layout Standard
1596 for every frame captured.
1597  Internally, 
1598 \emph on
1599 speex_echo_playback()
1600 \emph default
1601  simply buffers the playback frame so it can be used by 
1602 \emph on
1603 speex_echo_capture()
1604 \emph default
1605  to call 
1606 \emph on
1607 speex_echo_cancel()
1608 \emph default
1609 .
1610  When capture and playback are done synchronously, 
1611 \emph on
1612 speex_echo_cancel()
1613 \emph default
1614  is still prefered since it gives better control on the exact input/echo
1615  timing.
1616 \end_layout
1617
1618 \begin_layout Standard
1619 The echo cancellation state can be destroyed with:
1620 \end_layout
1621
1622 \begin_layout LyX-Code
1623 speex_echo_state_destroy(echo_state);
1624 \end_layout
1625
1626 \begin_layout Standard
1627 It is also possible to reset the state of the echo canceller so it can be
1628  reused without the need to create another state with:
1629 \end_layout
1630
1631 \begin_layout LyX-Code
1632 speex_echo_state_reset(echo_state);
1633 \end_layout
1634
1635 \begin_layout Subsubsection
1636 Troubleshooting
1637 \end_layout
1638
1639 \begin_layout Standard
1640 There are several things that may prevent the echo canceller from working
1641  properly.
1642  One of them is a bug (or something suboptimal) in the code, but there are
1643  many others you should consider first
1644 \end_layout
1645
1646 \begin_layout Itemize
1647 Using a different soundcard to do the capture and plaback will *not* work,
1648  regardless of what you may think.
1649  The only exception to that is if the two cards can be made to have their
1650  sampling clock 
1651 \begin_inset Quotes eld
1652 \end_inset
1653
1654 locked
1655 \begin_inset Quotes erd
1656 \end_inset
1657
1658  on the same clock source.
1659 \end_layout
1660
1661 \begin_layout Itemize
1662 The delay between the record and playback signals must be minimal.
1663  Any signal played has to 
1664 \begin_inset Quotes eld
1665 \end_inset
1666
1667 appear
1668 \begin_inset Quotes erd
1669 \end_inset
1670
1671  on the playback (far end) signal slightly before the echo canceller 
1672 \begin_inset Quotes eld
1673 \end_inset
1674
1675 sees
1676 \begin_inset Quotes erd
1677 \end_inset
1678
1679  it in the near end signal, but excessive delay means that part of the filter
1680  length is wasted.
1681  In the worst situations, the delay is such that it is longer than the filter
1682  length, in which case, no echo can be cancelled.
1683 \end_layout
1684
1685 \begin_layout Itemize
1686 When it comes to echo tail length (filter length), longer is *not* better.
1687  Actually, the longer the tail length, the longer it takes for the filter
1688  to adapt.
1689  Of course, a tail length that is too short will not cancel enough echo,
1690  but the most common problem seen is that people set a very long tail length
1691  and then wonder why no echo is being cancelled.
1692 \end_layout
1693
1694 \begin_layout Itemize
1695 Non-linear distortion cannot (by definition) be modeled by the linear adaptive
1696  filter used in the echo canceller and thus cannot be cancelled.
1697  Use good audio gear and avoid saturation/clipping.
1698 \end_layout
1699
1700 \begin_layout Standard
1701 Also useful is reading 
1702 \emph on
1703 Echo Cancellation Demystified
1704 \emph default
1705  by Alexey Frunze
1706 \begin_inset Foot
1707 status collapsed
1708
1709 \begin_layout Standard
1710 http://www.embeddedstar.com/articles/2003/7/article20030720-1.html
1711 \end_layout
1712
1713 \end_inset
1714
1715 , which explains the fundamental principles of echo cancellation.
1716  The details of the algorithm described in the article are different, but
1717  the general ideas of echo cancellation through adaptive filters are the
1718  same.
1719 \end_layout
1720
1721 \begin_layout Subsection
1722 Codec Options (speex_*_ctl)
1723 \begin_inset LatexCommand \label{sub:Codec-Options}
1724
1725 \end_inset
1726
1727
1728 \end_layout
1729
1730 \begin_layout Standard
1731 The Speex encoder and decoder support many options and requests that can
1732  be accessed through the 
1733 \emph on
1734 speex_encoder_ctl
1735 \emph default
1736  and 
1737 \emph on
1738 speex_decoder_ctl
1739 \emph default
1740  functions.
1741  These functions are similar to the 
1742 \emph on
1743 ioctl
1744 \emph default
1745  system call and their prototypes are:
1746 \end_layout
1747
1748 \begin_layout LyX-Code
1749 void speex_encoder_ctl(void *encoder, int request, void *ptr);
1750 \end_layout
1751
1752 \begin_layout LyX-Code
1753 void speex_decoder_ctl(void *encoder, int request, void *ptr);
1754 \end_layout
1755
1756 \begin_layout Standard
1757 The different values of request allowed are (note that some only apply to
1758  the encoder or the decoder):
1759 \end_layout
1760
1761 \begin_layout Description
1762 SPEEX_SET_ENH** Set perceptual enhancer
1763 \begin_inset LatexCommand \index{perceptual enhancement}
1764
1765 \end_inset
1766
1767  to on (1) or off (0) (integer)
1768 \end_layout
1769
1770 \begin_layout Description
1771 SPEEX_GET_ENH** Get perceptual enhancer status (integer)
1772 \end_layout
1773
1774 \begin_layout Description
1775 SPEEX_GET_FRAME_SIZE Get the frame size used for the current mode (integer)
1776 \end_layout
1777
1778 \begin_layout Description
1779 SPEEX_SET_QUALITY* Set the encoder speech quality (integer 0 to 10)
1780 \end_layout
1781
1782 \begin_layout Description
1783 SPEEX_GET_QUALITY* Get the current encoder speech quality (integer 0 to
1784  10)
1785 \end_layout
1786
1787 \begin_layout Description
1788 SPEEX_SET_MODE*
1789 \begin_inset Formula $\dagger$
1790 \end_inset
1791
1792
1793 \end_layout
1794
1795 \begin_layout Description
1796 SPEEX_GET_MODE*
1797 \begin_inset Formula $\dagger$
1798 \end_inset
1799
1800
1801 \end_layout
1802
1803 \begin_layout Description
1804 SPEEX_SET_LOW_MODE*
1805 \begin_inset Formula $\dagger$
1806 \end_inset
1807
1808
1809 \end_layout
1810
1811 \begin_layout Description
1812 SPEEX_GET_LOW_MODE*
1813 \begin_inset Formula $\dagger$
1814 \end_inset
1815
1816
1817 \end_layout
1818
1819 \begin_layout Description
1820 SPEEX_SET_HIGH_MODE*
1821 \begin_inset Formula $\dagger$
1822 \end_inset
1823
1824
1825 \end_layout
1826
1827 \begin_layout Description
1828 SPEEX_GET_HIGH_MODE*
1829 \begin_inset Formula $\dagger$
1830 \end_inset
1831
1832
1833 \end_layout
1834
1835 \begin_layout Description
1836 SPEEX_SET_VBR* Set variable bit-rate (VBR) to on (1) or off (0) (integer)
1837 \end_layout
1838
1839 \begin_layout Description
1840 SPEEX_GET_VBR* Get variable bit-rate
1841 \begin_inset LatexCommand \index{variable bit-rate}
1842
1843 \end_inset
1844
1845  (VBR) status (integer)
1846 \end_layout
1847
1848 \begin_layout Description
1849 SPEEX_SET_VBR_QUALITY* Set the encoder VBR speech quality (float 0 to 10)
1850 \end_layout
1851
1852 \begin_layout Description
1853 SPEEX_GET_VBR_QUALITY* Get the current encoder VBR speech quality (float
1854  0 to 10)
1855 \end_layout
1856
1857 \begin_layout Description
1858 SPEEX_SET_COMPLEXITY* Set the CPU resources allowed for the encoder (integer
1859  1 to 10)
1860 \end_layout
1861
1862 \begin_layout Description
1863 SPEEX_GET_COMPLEXITY* Get the CPU resources allowed for the encoder (integer
1864  1 to 10)
1865 \end_layout
1866
1867 \begin_layout Description
1868 SPEEX_SET_BITRATE* Set the bit-rate to use to the closest value not exceeding
1869  the parameter (integer in bps)
1870 \end_layout
1871
1872 \begin_layout Description
1873 SPEEX_GET_BITRATE Get the current bit-rate in use (integer in bps)
1874 \end_layout
1875
1876 \begin_layout Description
1877 SPEEX_SET_SAMPLING_RATE Set real sampling rate (integer in Hz)
1878 \end_layout
1879
1880 \begin_layout Description
1881 SPEEX_GET_SAMPLING_RATE Get real sampling rate (integer in Hz)
1882 \end_layout
1883
1884 \begin_layout Description
1885 SPEEX_RESET_STATE Reset the encoder/decoder state to its original state
1886  (zeros all memories)
1887 \end_layout
1888
1889 \begin_layout Description
1890 SPEEX_SET_VAD* Set voice activity detection
1891 \begin_inset LatexCommand \index{voice activity detection}
1892
1893 \end_inset
1894
1895  (VAD) to on (1) or off (0) (integer)
1896 \end_layout
1897
1898 \begin_layout Description
1899 SPEEX_GET_VAD* Get voice activity detection (VAD) status (integer)
1900 \end_layout
1901
1902 \begin_layout Description
1903 SPEEX_SET_DTX* Set discontinuous transmission
1904 \begin_inset LatexCommand \index{discontinuous transmission}
1905
1906 \end_inset
1907
1908  (DTX) to on (1) or off (0) (integer)
1909 \end_layout
1910
1911 \begin_layout Description
1912 SPEEX_GET_DTX* Get discontinuous transmission (DTX) status (integer)
1913 \end_layout
1914
1915 \begin_layout Description
1916 SPEEX_SET_ABR* Set average bit-rate
1917 \begin_inset LatexCommand \index{average bit-rate}
1918
1919 \end_inset
1920
1921  (ABR) to a value n in bits per second (integer in bps)
1922 \end_layout
1923
1924 \begin_layout Description
1925 SPEEX_GET_ABR* Get average bit-rate (ABR) setting (integer in bps)
1926 \end_layout
1927
1928 \begin_layout Description
1929 SPEEX_SET_PLC_TUNING* Tell the encoder to optimize encoding for a certain
1930  percentage of packet loss (integer in percent)
1931 \end_layout
1932
1933 \begin_layout Description
1934 SPEEX_GET_PLC_TUNING* Get the current tuning of the encoder for PLC (integer
1935  in percent)
1936 \end_layout
1937
1938 \begin_layout Description
1939 * applies only to the encoder
1940 \end_layout
1941
1942 \begin_layout Description
1943 ** applies only to the decoder
1944 \end_layout
1945
1946 \begin_layout Description
1947 \begin_inset Formula $\dagger$
1948 \end_inset
1949
1950  normally only used internally
1951 \end_layout
1952
1953 \begin_layout Subsection
1954 Mode queries
1955 \begin_inset LatexCommand \label{sub:Mode-queries}
1956
1957 \end_inset
1958
1959
1960 \end_layout
1961
1962 \begin_layout Standard
1963 Speex modes have a query system similar to the speex_encoder_ctl and speex_decod
1964 er_ctl calls.
1965  Since modes are read-only, it is only possible to get information about
1966  a particular mode.
1967  The function used to do that is:
1968 \end_layout
1969
1970 \begin_layout LyX-Code
1971 void speex_mode_query(SpeexMode *mode, int request, void *ptr);
1972 \end_layout
1973
1974 \begin_layout Standard
1975 The admissible values for request are (unless otherwise note, the values
1976  are returned through 
1977 \emph on
1978 ptr
1979 \emph default
1980 ):
1981 \end_layout
1982
1983 \begin_layout Description
1984 SPEEX_MODE_FRAME_SIZE Get the frame size (in samples) for the mode
1985 \end_layout
1986
1987 \begin_layout Description
1988 SPEEX_SUBMODE_BITRATE Get the bit-rate for a submode number specified through
1989  
1990 \emph on
1991 ptr
1992 \emph default
1993  (integer in bps).
1994  
1995 \end_layout
1996
1997 \begin_layout Subsection
1998 Preprocessor options
1999 \begin_inset LatexCommand \label{sub:Preprocessor-options}
2000
2001 \end_inset
2002
2003
2004 \end_layout
2005
2006 \begin_layout Description
2007 SPEEX_PREPROCESS_SET_DENOISE Turns denoising on(1) or off(2) (integer)
2008 \end_layout
2009
2010 \begin_layout Description
2011 SPEEX_PREPROCESS_GET_DENOISE Get denoising status (integer)
2012 \end_layout
2013
2014 \begin_layout Description
2015 SPEEX_PREPROCESS_SET_AGC Turns automatic gain control (AGC) on(1) or off(2)
2016  (integer)
2017 \end_layout
2018
2019 \begin_layout Description
2020 SPEEX_PREPROCESS_GET_AGC Get AGC status (integer)
2021 \end_layout
2022
2023 \begin_layout Description
2024 SPEEX_PREPROCESS_SET_VAD Turns voice activity detector (VAD) on(1) or off(2)
2025  (integer)
2026 \end_layout
2027
2028 \begin_layout Description
2029 SPEEX_PREPROCESS_GET_VAD Get VAD status (integer)
2030 \end_layout
2031
2032 \begin_layout Description
2033 SPEEX_PREPROCESS_SET_AGC_LEVEL
2034 \end_layout
2035
2036 \begin_layout Description
2037 SPEEX_PREPROCESS_GET_AGC_LEVEL
2038 \end_layout
2039
2040 \begin_layout Description
2041 SPEEX_PREPROCESS_SET_DEREVERB Turns reverberation removal on(1) or off(2)
2042  (integer)
2043 \end_layout
2044
2045 \begin_layout Description
2046 SPEEX_PREPROCESS_GET_DEREVERB Get reverberation removal status (integer)
2047 \end_layout
2048
2049 \begin_layout Description
2050 SPEEX_PREPROCESS_SET_DEREVERB_LEVEL
2051 \end_layout
2052
2053 \begin_layout Description
2054 SPEEX_PREPROCESS_GET_DEREVERB_LEVEL
2055 \end_layout
2056
2057 \begin_layout Description
2058 SPEEX_PREPROCESS_SET_DEREVERB_DECAY
2059 \end_layout
2060
2061 \begin_layout Description
2062 SPEEX_PREPROCESS_GET_DEREVERB_DECAY
2063 \end_layout
2064
2065 \begin_layout Subsection
2066 Packing and in-band signalling
2067 \begin_inset LatexCommand \index{in-band signalling}
2068
2069 \end_inset
2070
2071
2072 \end_layout
2073
2074 \begin_layout Standard
2075 Sometimes it is desirable to pack more than one frame per packet (or other
2076  basic unit of storage).
2077  The proper way to do it is to call speex_encode 
2078 \begin_inset Formula $N$
2079 \end_inset
2080
2081  times before writing the stream with speex_bits_write.
2082  In cases where the number of frames is not determined by an out-of-band
2083  mechanism, it is possible to include a terminator code.
2084  That terminator consists of the code 15 (decimal) encoded with 5 bits,
2085  as shown in Table 
2086 \begin_inset LatexCommand \ref{cap:quality_vs_bps}
2087
2088 \end_inset
2089
2090 .
2091  Note that as of version 1.0.2, calling speex_bits_write automatically inserts
2092  the terminator so as to fill the last byte.
2093  This doesn't involves any overhead and makes sure Speex can always detect
2094  when there is no more frame in a packet.
2095 \end_layout
2096
2097 \begin_layout Standard
2098 It is also possible to send in-band 
2099 \begin_inset Quotes eld
2100 \end_inset
2101
2102 messages
2103 \begin_inset Quotes erd
2104 \end_inset
2105
2106  to the other side.
2107  All these messages are encoded as 
2108 \begin_inset Quotes eld
2109 \end_inset
2110
2111 pseudo-frames
2112 \begin_inset Quotes erd
2113 \end_inset
2114
2115  of mode 14 which contain a 4-bit message type code, followed by the message.
2116  Table 
2117 \begin_inset LatexCommand \ref{cap:In-band-signalling-codes}
2118
2119 \end_inset
2120
2121  lists the available codes, their meaning and the size of the message that
2122  follows.
2123  Most of these messages are requests that are sent to the encoder or decoder
2124  on the other end, which is free to comply or ignore them.
2125  By default, all in-band messages are ignored.
2126 \end_layout
2127
2128 \begin_layout Standard
2129 \begin_inset Float table
2130 placement htbp
2131 wide false
2132 sideways false
2133 status open
2134
2135 \begin_layout Standard
2136 \begin_inset Tabular
2137 <lyxtabular version="3" rows="17" columns="3">
2138 <features>
2139 <column alignment="center" valignment="top" leftline="true" width="0pt">
2140 <column alignment="center" valignment="top" leftline="true" width="0pt">
2141 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
2142 <row topline="true" bottomline="true">
2143 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2144 \begin_inset Text
2145
2146 \begin_layout Standard
2147 Code
2148 \end_layout
2149
2150 \end_inset
2151 </cell>
2152 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2153 \begin_inset Text
2154
2155 \begin_layout Standard
2156 Size (bits)
2157 \end_layout
2158
2159 \end_inset
2160 </cell>
2161 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2162 \begin_inset Text
2163
2164 \begin_layout Standard
2165 Content
2166 \end_layout
2167
2168 \end_inset
2169 </cell>
2170 </row>
2171 <row topline="true">
2172 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2173 \begin_inset Text
2174
2175 \begin_layout Standard
2176 0
2177 \end_layout
2178
2179 \end_inset
2180 </cell>
2181 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2182 \begin_inset Text
2183
2184 \begin_layout Standard
2185 1
2186 \end_layout
2187
2188 \end_inset
2189 </cell>
2190 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2191 \begin_inset Text
2192
2193 \begin_layout Standard
2194 Asks decoder to set perceptual enhancement off (0) or on(1)
2195 \end_layout
2196
2197 \end_inset
2198 </cell>
2199 </row>
2200 <row topline="true">
2201 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2202 \begin_inset Text
2203
2204 \begin_layout Standard
2205 1
2206 \end_layout
2207
2208 \end_inset
2209 </cell>
2210 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2211 \begin_inset Text
2212
2213 \begin_layout Standard
2214 1
2215 \end_layout
2216
2217 \end_inset
2218 </cell>
2219 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2220 \begin_inset Text
2221
2222 \begin_layout Standard
2223 Asks (if 1) the encoder to be less 
2224 \begin_inset Quotes eld
2225 \end_inset
2226
2227 agressive
2228 \begin_inset Quotes erd
2229 \end_inset
2230
2231  due to high packet loss
2232 \end_layout
2233
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 \begin_layout Standard
2242 2
2243 \end_layout
2244
2245 \end_inset
2246 </cell>
2247 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2248 \begin_inset Text
2249
2250 \begin_layout Standard
2251 4
2252 \end_layout
2253
2254 \end_inset
2255 </cell>
2256 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2257 \begin_inset Text
2258
2259 \begin_layout Standard
2260 Asks encoder to switch to mode N
2261 \end_layout
2262
2263 \end_inset
2264 </cell>
2265 </row>
2266 <row topline="true">
2267 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2268 \begin_inset Text
2269
2270 \begin_layout Standard
2271 3
2272 \end_layout
2273
2274 \end_inset
2275 </cell>
2276 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2277 \begin_inset Text
2278
2279 \begin_layout Standard
2280 4
2281 \end_layout
2282
2283 \end_inset
2284 </cell>
2285 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2286 \begin_inset Text
2287
2288 \begin_layout Standard
2289 Asks encoder to switch to mode N for low-band
2290 \end_layout
2291
2292 \end_inset
2293 </cell>
2294 </row>
2295 <row topline="true">
2296 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2297 \begin_inset Text
2298
2299 \begin_layout Standard
2300 4
2301 \end_layout
2302
2303 \end_inset
2304 </cell>
2305 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2306 \begin_inset Text
2307
2308 \begin_layout Standard
2309 4
2310 \end_layout
2311
2312 \end_inset
2313 </cell>
2314 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2315 \begin_inset Text
2316
2317 \begin_layout Standard
2318 Asks encoder to switch to mode N for high-band
2319 \end_layout
2320
2321 \end_inset
2322 </cell>
2323 </row>
2324 <row topline="true">
2325 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2326 \begin_inset Text
2327
2328 \begin_layout Standard
2329 5
2330 \end_layout
2331
2332 \end_inset
2333 </cell>
2334 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2335 \begin_inset Text
2336
2337 \begin_layout Standard
2338 4
2339 \end_layout
2340
2341 \end_inset
2342 </cell>
2343 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2344 \begin_inset Text
2345
2346 \begin_layout Standard
2347 Asks encoder to switch to quality N for VBR
2348 \end_layout
2349
2350 \end_inset
2351 </cell>
2352 </row>
2353 <row topline="true">
2354 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2355 \begin_inset Text
2356
2357 \begin_layout Standard
2358 6
2359 \end_layout
2360
2361 \end_inset
2362 </cell>
2363 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2364 \begin_inset Text
2365
2366 \begin_layout Standard
2367 4
2368 \end_layout
2369
2370 \end_inset
2371 </cell>
2372 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2373 \begin_inset Text
2374
2375 \begin_layout Standard
2376 Request acknowloedge (0=no, 1=all, 2=only for in-band data)
2377 \end_layout
2378
2379 \end_inset
2380 </cell>
2381 </row>
2382 <row topline="true">
2383 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2384 \begin_inset Text
2385
2386 \begin_layout Standard
2387 7
2388 \end_layout
2389
2390 \end_inset
2391 </cell>
2392 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2393 \begin_inset Text
2394
2395 \begin_layout Standard
2396 4
2397 \end_layout
2398
2399 \end_inset
2400 </cell>
2401 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2402 \begin_inset Text
2403
2404 \begin_layout Standard
2405 Asks encoder to set CBR (0), VAD(1), DTX(3), VBR(5), VBR+DTX(7)
2406 \end_layout
2407
2408 \end_inset
2409 </cell>
2410 </row>
2411 <row topline="true">
2412 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2413 \begin_inset Text
2414
2415 \begin_layout Standard
2416 8
2417 \end_layout
2418
2419 \end_inset
2420 </cell>
2421 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2422 \begin_inset Text
2423
2424 \begin_layout Standard
2425 8
2426 \end_layout
2427
2428 \end_inset
2429 </cell>
2430 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2431 \begin_inset Text
2432
2433 \begin_layout Standard
2434 Transmit (8-bit) character to the other end
2435 \end_layout
2436
2437 \end_inset
2438 </cell>
2439 </row>
2440 <row topline="true">
2441 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2442 \begin_inset Text
2443
2444 \begin_layout Standard
2445 9
2446 \end_layout
2447
2448 \end_inset
2449 </cell>
2450 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2451 \begin_inset Text
2452
2453 \begin_layout Standard
2454 8
2455 \end_layout
2456
2457 \end_inset
2458 </cell>
2459 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2460 \begin_inset Text
2461
2462 \begin_layout Standard
2463 Intensity stereo information
2464 \end_layout
2465
2466 \end_inset
2467 </cell>
2468 </row>
2469 <row topline="true">
2470 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2471 \begin_inset Text
2472
2473 \begin_layout Standard
2474 10
2475 \end_layout
2476
2477 \end_inset
2478 </cell>
2479 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2480 \begin_inset Text
2481
2482 \begin_layout Standard
2483 16
2484 \end_layout
2485
2486 \end_inset
2487 </cell>
2488 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2489 \begin_inset Text
2490
2491 \begin_layout Standard
2492 Announce maximum bit-rate acceptable (N in bytes/second)
2493 \end_layout
2494
2495 \end_inset
2496 </cell>
2497 </row>
2498 <row topline="true">
2499 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2500 \begin_inset Text
2501
2502 \begin_layout Standard
2503 11
2504 \end_layout
2505
2506 \end_inset
2507 </cell>
2508 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2509 \begin_inset Text
2510
2511 \begin_layout Standard
2512 16
2513 \end_layout
2514
2515 \end_inset
2516 </cell>
2517 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2518 \begin_inset Text
2519
2520 \begin_layout Standard
2521 reserved
2522 \end_layout
2523
2524 \end_inset
2525 </cell>
2526 </row>
2527 <row topline="true">
2528 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2529 \begin_inset Text
2530
2531 \begin_layout Standard
2532 12
2533 \end_layout
2534
2535 \end_inset
2536 </cell>
2537 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2538 \begin_inset Text
2539
2540 \begin_layout Standard
2541 32
2542 \end_layout
2543
2544 \end_inset
2545 </cell>
2546 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2547 \begin_inset Text
2548
2549 \begin_layout Standard
2550 Acknowledge receiving packet N
2551 \end_layout
2552
2553 \end_inset
2554 </cell>
2555 </row>
2556 <row topline="true">
2557 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2558 \begin_inset Text
2559
2560 \begin_layout Standard
2561 13
2562 \end_layout
2563
2564 \end_inset
2565 </cell>
2566 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2567 \begin_inset Text
2568
2569 \begin_layout Standard
2570 32
2571 \end_layout
2572
2573 \end_inset
2574 </cell>
2575 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2576 \begin_inset Text
2577
2578 \begin_layout Standard
2579 reserved
2580 \end_layout
2581
2582 \end_inset
2583 </cell>
2584 </row>
2585 <row topline="true">
2586 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2587 \begin_inset Text
2588
2589 \begin_layout Standard
2590 14
2591 \end_layout
2592
2593 \end_inset
2594 </cell>
2595 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2596 \begin_inset Text
2597
2598 \begin_layout Standard
2599 64
2600 \end_layout
2601
2602 \end_inset
2603 </cell>
2604 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2605 \begin_inset Text
2606
2607 \begin_layout Standard
2608 reserved
2609 \end_layout
2610
2611 \end_inset
2612 </cell>
2613 </row>
2614 <row topline="true" bottomline="true">
2615 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2616 \begin_inset Text
2617
2618 \begin_layout Standard
2619 15
2620 \end_layout
2621
2622 \end_inset
2623 </cell>
2624 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2625 \begin_inset Text
2626
2627 \begin_layout Standard
2628 64
2629 \end_layout
2630
2631 \end_inset
2632 </cell>
2633 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2634 \begin_inset Text
2635
2636 \begin_layout Standard
2637 reserved
2638 \end_layout
2639
2640 \end_inset
2641 </cell>
2642 </row>
2643 </lyxtabular>
2644
2645 \end_inset
2646
2647
2648 \end_layout
2649
2650 \begin_layout Caption
2651 In-band signalling codes
2652 \begin_inset LatexCommand \label{cap:In-band-signalling-codes}
2653
2654 \end_inset
2655
2656
2657 \end_layout
2658
2659 \end_inset
2660
2661
2662 \end_layout
2663
2664 \begin_layout Standard
2665 Finally, applications may define custom in-band messages using mode 13.
2666  The size of the message in bytes is encoded with 5 bits, so that the decoder
2667  can skip it if it doesn't know how to interpret it.
2668 \end_layout
2669
2670 \begin_layout Standard
2671
2672 \newpage
2673
2674 \end_layout
2675
2676 \begin_layout Section
2677 Formats and standards
2678 \begin_inset LatexCommand \index{standards}
2679
2680 \end_inset
2681
2682
2683 \begin_inset LatexCommand \label{sec:Formats-and-standards}
2684
2685 \end_inset
2686
2687
2688 \end_layout
2689
2690 \begin_layout Standard
2691 Speex can encode speech in both narrowband and wideband and provides different
2692  bit-rates.
2693  However, not all features need to be supported by a certain implementation
2694  or device.
2695  In order to be called 
2696 \begin_inset Quotes eld
2697 \end_inset
2698
2699 Speex compatible
2700 \begin_inset Quotes erd
2701 \end_inset
2702
2703  (whatever that means), an implementation must implement at least a basic
2704  set of features.
2705 \end_layout
2706
2707 \begin_layout Standard
2708 At the minimum, all narrowband modes of operation MUST be supported at the
2709  decoder.
2710  This includes the decoding of a wideband bit-stream by the narrowband decoder
2711 \begin_inset Foot
2712 status collapsed
2713
2714 \begin_layout Standard
2715 The wideband bit-stream contains an embedded narrowband bit-stream which
2716  can be decoded alone
2717 \end_layout
2718
2719 \end_inset
2720
2721 .
2722  If present, a wideband decoder MUST be able to decode a narrowband stream,
2723  and MAY either be able to decode all wideband modes or be able to decode
2724  the embedded narrowband part of all modes (which includes ignoring the
2725  high-band bits).
2726 \end_layout
2727
2728 \begin_layout Standard
2729 For encoders, at least one narrowband or wideband mode MUST be supported.
2730  The main reason why all encoding modes do not have to be supported is that
2731  some platforms may not be able to handle the complexity of encoding in
2732  some modes.
2733 \end_layout
2734
2735 \begin_layout Subsection
2736 RTP
2737 \begin_inset LatexCommand \index{RTP}
2738
2739 \end_inset
2740
2741  Payload Format 
2742 \end_layout
2743
2744 \begin_layout Standard
2745 The RTP payload draft is included in appendix 
2746 \begin_inset LatexCommand \ref{sec:IETF-draft}
2747
2748 \end_inset
2749
2750  and the latest version is available at 
2751 \begin_inset LatexCommand \url{http://www.speex.org/drafts/latest}
2752
2753 \end_inset
2754
2755 .
2756  This draft has been sent (2003/02/26) to the Internet Engineering Task
2757  Force (IETF) and will be discussed at the March 18th meeting in San Francisco.
2758  
2759 \end_layout
2760
2761 \begin_layout Subsection
2762 MIME Type
2763 \end_layout
2764
2765 \begin_layout Standard
2766 For now, you should use the MIME type audio/x-speex for Speex-in-Ogg.
2767  We will apply for type 
2768 \family typewriter
2769 audio/speex
2770 \family default
2771  in the near future.
2772 \end_layout
2773
2774 \begin_layout Subsection
2775 Ogg
2776 \begin_inset LatexCommand \index{Ogg}
2777
2778 \end_inset
2779
2780  file format
2781 \end_layout
2782
2783 \begin_layout Standard
2784 Speex bit-streams can be stored in Ogg files.
2785  In this case, the first packet of the Ogg file contains the Speex header
2786  described in table 
2787 \begin_inset LatexCommand \ref{cap:ogg_speex_header}
2788
2789 \end_inset
2790
2791 .
2792  All integer fields in the headers are stored as little-endian.
2793  The 
2794 \family typewriter
2795 speex_string
2796 \family default
2797  field must contain the 
2798 \begin_inset Quotes eld
2799 \end_inset
2800
2801
2802 \family typewriter
2803 Speex
2804 \family default
2805 \InsetSpace ~
2806 \InsetSpace ~
2807 \InsetSpace ~
2808
2809 \begin_inset Quotes erd
2810 \end_inset
2811
2812  (with 3 trailing spaces), which identifies the bit-stream.
2813  The next field, 
2814 \family typewriter
2815 speex_version
2816 \family default
2817  contains the version of Speex that encoded the file.
2818  For now, refer to speex_header.[ch] for more info.
2819  The 
2820 \emph on
2821 beginning of stream
2822 \emph default
2823  (
2824 \family typewriter
2825 b_o_s
2826 \family default
2827 ) flag is set to 1 for the header.
2828  The header packet has 
2829 \family typewriter
2830 packetno=0
2831 \family default
2832  and 
2833 \family typewriter
2834 granulepos=0
2835 \family default
2836 .
2837 \end_layout
2838
2839 \begin_layout Standard
2840 The second packet contains the Speex comment header.
2841  The format used is the Vorbis comment format described here: http://www.xiph.org/
2842 ogg/vorbis/doc/v-comment.html .
2843  This packet has 
2844 \family typewriter
2845 packetno=1
2846 \family default
2847  and 
2848 \family typewriter
2849 granulepos=0
2850 \family default
2851 .
2852 \end_layout
2853
2854 \begin_layout Standard
2855 The third and subsequent packets each contain one or more (number found
2856  in header) Speex frames.
2857  These are identified with 
2858 \family typewriter
2859 packetno
2860 \family default
2861  starting from 2 and the 
2862 \family typewriter
2863 granulepos
2864 \family default
2865  is the number of the last sample encoded in that packet.
2866  The last of these packets has the 
2867 \emph on
2868 end of stream
2869 \emph default
2870  (
2871 \family typewriter
2872 e_o_s
2873 \family default
2874 ) flag is set to 1.
2875 \end_layout
2876
2877 \begin_layout Standard
2878 \begin_inset Float table
2879 placement htbp
2880 wide true
2881 sideways false
2882 status open
2883
2884 \begin_layout Standard
2885 \begin_inset Tabular
2886 <lyxtabular version="3" rows="16" columns="3">
2887 <features>
2888 <column alignment="center" valignment="top" leftline="true" width="0pt">
2889 <column alignment="center" valignment="top" leftline="true" width="0pt">
2890 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
2891 <row topline="true" bottomline="true">
2892 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2893 \begin_inset Text
2894
2895 \begin_layout Standard
2896 Field
2897 \end_layout
2898
2899 \end_inset
2900 </cell>
2901 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2902 \begin_inset Text
2903
2904 \begin_layout Standard
2905 Type
2906 \end_layout
2907
2908 \end_inset
2909 </cell>
2910 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2911 \begin_inset Text
2912
2913 \begin_layout Standard
2914 Size
2915 \end_layout
2916
2917 \end_inset
2918 </cell>
2919 </row>
2920 <row topline="true">
2921 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2922 \begin_inset Text
2923
2924 \begin_layout Standard
2925 speex_string
2926 \end_layout
2927
2928 \end_inset
2929 </cell>
2930 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2931 \begin_inset Text
2932
2933 \begin_layout Standard
2934 char[]
2935 \end_layout
2936
2937 \end_inset
2938 </cell>
2939 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2940 \begin_inset Text
2941
2942 \begin_layout Standard
2943 8
2944 \end_layout
2945
2946 \end_inset
2947 </cell>
2948 </row>
2949 <row topline="true">
2950 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2951 \begin_inset Text
2952
2953 \begin_layout Standard
2954 speex_version
2955 \end_layout
2956
2957 \end_inset
2958 </cell>
2959 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2960 \begin_inset Text
2961
2962 \begin_layout Standard
2963 char[]
2964 \end_layout
2965
2966 \end_inset
2967 </cell>
2968 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2969 \begin_inset Text
2970
2971 \begin_layout Standard
2972 20
2973 \end_layout
2974
2975 \end_inset
2976 </cell>
2977 </row>
2978 <row topline="true">
2979 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2980 \begin_inset Text
2981
2982 \begin_layout Standard
2983 speex_version_id
2984 \end_layout
2985
2986 \end_inset
2987 </cell>
2988 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2989 \begin_inset Text
2990
2991 \begin_layout Standard
2992 int
2993 \end_layout
2994
2995 \end_inset
2996 </cell>
2997 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2998 \begin_inset Text
2999
3000 \begin_layout Standard
3001 4
3002 \end_layout
3003
3004 \end_inset
3005 </cell>
3006 </row>
3007 <row topline="true">
3008 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3009 \begin_inset Text
3010
3011 \begin_layout Standard
3012 header_size
3013 \end_layout
3014
3015 \end_inset
3016 </cell>
3017 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3018 \begin_inset Text
3019
3020 \begin_layout Standard
3021 int
3022 \end_layout
3023
3024 \end_inset
3025 </cell>
3026 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3027 \begin_inset Text
3028
3029 \begin_layout Standard
3030 4
3031 \end_layout
3032
3033 \end_inset
3034 </cell>
3035 </row>
3036 <row topline="true">
3037 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3038 \begin_inset Text
3039
3040 \begin_layout Standard
3041 rate
3042 \end_layout
3043
3044 \end_inset
3045 </cell>
3046 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3047 \begin_inset Text
3048
3049 \begin_layout Standard
3050 int
3051 \end_layout
3052
3053 \end_inset
3054 </cell>
3055 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3056 \begin_inset Text
3057
3058 \begin_layout Standard
3059 4
3060 \end_layout
3061
3062 \end_inset
3063 </cell>
3064 </row>
3065 <row topline="true">
3066 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3067 \begin_inset Text
3068
3069 \begin_layout Standard
3070 mode
3071 \end_layout
3072
3073 \end_inset
3074 </cell>
3075 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3076 \begin_inset Text
3077
3078 \begin_layout Standard
3079 int
3080 \end_layout
3081
3082 \end_inset
3083 </cell>
3084 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3085 \begin_inset Text
3086
3087 \begin_layout Standard
3088 4
3089 \end_layout
3090
3091 \end_inset
3092 </cell>
3093 </row>
3094 <row topline="true">
3095 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3096 \begin_inset Text
3097
3098 \begin_layout Standard
3099 mode_bitstream_version
3100 \end_layout
3101
3102 \end_inset
3103 </cell>
3104 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3105 \begin_inset Text
3106
3107 \begin_layout Standard
3108 int
3109 \end_layout
3110
3111 \end_inset
3112 </cell>
3113 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3114 \begin_inset Text
3115
3116 \begin_layout Standard
3117 4
3118 \end_layout
3119
3120 \end_inset
3121 </cell>
3122 </row>
3123 <row topline="true">
3124 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3125 \begin_inset Text
3126
3127 \begin_layout Standard
3128 nb_channels
3129 \end_layout
3130
3131 \end_inset
3132 </cell>
3133 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3134 \begin_inset Text
3135
3136 \begin_layout Standard
3137 int
3138 \end_layout
3139
3140 \end_inset
3141 </cell>
3142 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3143 \begin_inset Text
3144
3145 \begin_layout Standard
3146 4
3147 \end_layout
3148
3149 \end_inset
3150 </cell>
3151 </row>
3152 <row topline="true">
3153 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3154 \begin_inset Text
3155
3156 \begin_layout Standard
3157 bitrate
3158 \end_layout
3159
3160 \end_inset
3161 </cell>
3162 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3163 \begin_inset Text
3164
3165 \begin_layout Standard
3166 int
3167 \end_layout
3168
3169 \end_inset
3170 </cell>
3171 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3172 \begin_inset Text
3173
3174 \begin_layout Standard
3175 4
3176 \end_layout
3177
3178 \end_inset
3179 </cell>
3180 </row>
3181 <row topline="true">
3182 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3183 \begin_inset Text
3184
3185 \begin_layout Standard
3186 frame_size
3187 \end_layout
3188
3189 \end_inset
3190 </cell>
3191 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3192 \begin_inset Text
3193
3194 \begin_layout Standard
3195 int
3196 \end_layout
3197
3198 \end_inset
3199 </cell>
3200 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3201 \begin_inset Text
3202
3203 \begin_layout Standard
3204 4
3205 \end_layout
3206
3207 \end_inset
3208 </cell>
3209 </row>
3210 <row topline="true">
3211 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3212 \begin_inset Text
3213
3214 \begin_layout Standard
3215 vbr
3216 \end_layout
3217
3218 \end_inset
3219 </cell>
3220 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3221 \begin_inset Text
3222
3223 \begin_layout Standard
3224 int
3225 \end_layout
3226
3227 \end_inset
3228 </cell>
3229 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3230 \begin_inset Text
3231
3232 \begin_layout Standard
3233 4
3234 \end_layout
3235
3236 \end_inset
3237 </cell>
3238 </row>
3239 <row topline="true">
3240 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3241 \begin_inset Text
3242
3243 \begin_layout Standard
3244 frames_per_packet
3245 \end_layout
3246
3247 \end_inset
3248 </cell>
3249 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3250 \begin_inset Text
3251
3252 \begin_layout Standard
3253 int
3254 \end_layout
3255
3256 \end_inset
3257 </cell>
3258 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3259 \begin_inset Text
3260
3261 \begin_layout Standard
3262 4
3263 \end_layout
3264
3265 \end_inset
3266 </cell>
3267 </row>
3268 <row topline="true">
3269 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3270 \begin_inset Text
3271
3272 \begin_layout Standard
3273 extra_headers
3274 \end_layout
3275
3276 \end_inset
3277 </cell>
3278 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3279 \begin_inset Text
3280
3281 \begin_layout Standard
3282 int
3283 \end_layout
3284
3285 \end_inset
3286 </cell>
3287 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3288 \begin_inset Text
3289
3290 \begin_layout Standard
3291 4
3292 \end_layout
3293
3294 \end_inset
3295 </cell>
3296 </row>
3297 <row topline="true">
3298 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3299 \begin_inset Text
3300
3301 \begin_layout Standard
3302 reserved1
3303 \end_layout
3304
3305 \end_inset
3306 </cell>
3307 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3308 \begin_inset Text
3309
3310 \begin_layout Standard
3311 int
3312 \end_layout
3313
3314 \end_inset
3315 </cell>
3316 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3317 \begin_inset Text
3318
3319 \begin_layout Standard
3320 4
3321 \end_layout
3322
3323 \end_inset
3324 </cell>
3325 </row>
3326 <row topline="true" bottomline="true">
3327 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3328 \begin_inset Text
3329
3330 \begin_layout Standard
3331 reserved2
3332 \end_layout
3333
3334 \end_inset
3335 </cell>
3336 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3337 \begin_inset Text
3338
3339 \begin_layout Standard
3340 int
3341 \end_layout
3342
3343 \end_inset
3344 </cell>
3345 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3346 \begin_inset Text
3347
3348 \begin_layout Standard
3349 4
3350 \end_layout
3351
3352 \end_inset
3353 </cell>
3354 </row>
3355 </lyxtabular>
3356
3357 \end_inset
3358
3359
3360 \end_layout
3361
3362 \begin_layout Caption
3363 Ogg/Speex header packet
3364 \begin_inset LatexCommand \label{cap:ogg_speex_header}
3365
3366 \end_inset
3367
3368
3369 \end_layout
3370
3371 \end_inset
3372
3373
3374 \end_layout
3375
3376 \begin_layout Standard
3377
3378 \newpage
3379
3380 \end_layout
3381
3382 \begin_layout Section
3383 Introduction to CELP Coding
3384 \begin_inset LatexCommand \index{CELP}
3385
3386 \end_inset
3387
3388
3389 \begin_inset LatexCommand \label{sec:Introduction-to-CELP}
3390
3391 \end_inset
3392
3393
3394 \end_layout
3395
3396 \begin_layout Standard
3397 Speex is based on CELP, which stands for Code Excited Linear Prediction.
3398  This section attempts to introduce the principles behind CELP, so if you
3399  are already familiar with CELP, you can safely skip to section 
3400 \begin_inset LatexCommand \ref{sec:Speex-narrowband-mode}
3401
3402 \end_inset
3403
3404 .
3405  The CELP technique is based on three ideas:
3406 \end_layout
3407
3408 \begin_layout Enumerate
3409 The use of a linear prediction (LP) model to model the vocal tract
3410 \end_layout
3411
3412 \begin_layout Enumerate
3413 The use of (adaptive and fixed) codebook entries as input (excitation) of
3414  the LP model
3415 \end_layout
3416
3417 \begin_layout Enumerate
3418 The search performed in closed-loop in a 
3419 \begin_inset Quotes eld
3420 \end_inset
3421
3422 perceptually weighted domain
3423 \begin_inset Quotes erd
3424 \end_inset
3425
3426
3427 \end_layout
3428
3429 \begin_layout Standard
3430 This section describes the basic ideas behind CELP.
3431  Note that it's still incomplete.
3432 \end_layout
3433
3434 \begin_layout Subsection
3435 Linear Prediction (LPC)
3436 \begin_inset LatexCommand \index{linear prediction}
3437
3438 \end_inset
3439
3440
3441 \end_layout
3442
3443 \begin_layout Standard
3444 Linear prediction is at the base of many speech coding techniques, including
3445  CELP.
3446  The idea behind it is to predict the signal 
3447 \begin_inset Formula $x[n]$
3448 \end_inset
3449
3450  using a linear combination of its past samples:
3451 \end_layout
3452
3453 \begin_layout Standard
3454 \begin_inset Formula \[
3455 y[n]=\sum_{i=1}^{N}a_{i}x[n-i]\]
3456
3457 \end_inset
3458
3459 where 
3460 \begin_inset Formula $y[n]$
3461 \end_inset
3462
3463  is the linear prediction of 
3464 \begin_inset Formula $x[n]$
3465 \end_inset
3466
3467 .
3468  The prediction error is thus given by:
3469 \begin_inset Formula \[
3470 e[n]=x[n]-y[n]=x[n]-\sum_{i=1}^{N}a_{i}x[n-i]\]
3471
3472 \end_inset
3473
3474
3475 \end_layout
3476
3477 \begin_layout Standard
3478 The goal of the LPC analysis is to find the best prediction coefficients
3479  
3480 \begin_inset Formula $a_{i}$
3481 \end_inset
3482
3483  which minimize the quadratic error function:
3484 \begin_inset Formula \[
3485 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}\]
3486
3487 \end_inset
3488
3489 That can be done by making all derivatives 
3490 \begin_inset Formula $\frac{\partial E}{\partial a_{i}}$
3491 \end_inset
3492
3493  equal to zero:
3494 \begin_inset Formula \[
3495 \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\]
3496
3497 \end_inset
3498
3499
3500 \end_layout
3501
3502 \begin_layout Standard
3503 The 
3504 \begin_inset Formula $a_{i}$
3505 \end_inset
3506
3507  filter coefficients are computed using the Levinson-Durbin
3508 \begin_inset LatexCommand \index{Levinson-Durbin}
3509
3510 \end_inset
3511
3512  algorithm, which starts from the auto-correlation
3513 \begin_inset LatexCommand \index{auto-correlation}
3514
3515 \end_inset
3516
3517  
3518 \begin_inset Formula $R(m)$
3519 \end_inset
3520
3521  of the signal 
3522 \begin_inset Formula $x[n]$
3523 \end_inset
3524
3525 .
3526 \end_layout
3527
3528 \begin_layout Standard
3529 \begin_inset Formula \[
3530 R(m)=\sum_{i=0}^{N-1}x[i]x[i-m]\]
3531
3532 \end_inset
3533
3534
3535 \end_layout
3536
3537 \begin_layout Standard
3538 For an order 
3539 \begin_inset Formula $N$
3540 \end_inset
3541
3542  filter, we have:
3543 \begin_inset Formula \[
3544 \mathbf{R}=\left[\begin{array}{cccc}
3545 R(0) & R(1) & \cdots & R(N-1)\\
3546 R(1) & R(0) & \cdots & R(N-2)\\
3547 \vdots & \vdots & \ddots & \vdots\\
3548 R(N-1) & R(N-2) & \cdots & R(0)\end{array}\right]\]
3549
3550 \end_inset
3551
3552
3553 \begin_inset Formula \[
3554 \mathbf{r}=\left[\begin{array}{c}
3555 R(1)\\
3556 R(2)\\
3557 \vdots\\
3558 R(N)\end{array}\right]\]
3559
3560 \end_inset
3561
3562
3563 \end_layout
3564
3565 \begin_layout Standard
3566 The filter coefficients 
3567 \begin_inset Formula $a_{i}$
3568 \end_inset
3569
3570  are found by solving the system 
3571 \begin_inset Formula $\mathbf{Ra}=\mathbf{r}$
3572 \end_inset
3573
3574 .
3575  What the Levinson-Durbin algorithm does here is making the solution to
3576  the problem 
3577 \begin_inset Formula $\mathcal{O}\left(N^{2}\right)$
3578 \end_inset
3579
3580  instead of 
3581 \begin_inset Formula $\mathcal{O}\left(N^{3}\right)$
3582 \end_inset
3583
3584  by exploiting the fact that matrix 
3585 \begin_inset Formula $\mathbf{R}$
3586 \end_inset
3587
3588  is toeplitz hermitian.
3589  Also, it can be proven that all the roots of 
3590 \begin_inset Formula $A(z)$
3591 \end_inset
3592
3593  are within the unit circle, which means that 
3594 \begin_inset Formula $1/A(z)$
3595 \end_inset
3596
3597  is always stable.
3598  This is in theory; in practice because of finite precision, there are two
3599  commonly used techniques to make sure we have a stable filter.
3600  First, we multiply 
3601 \begin_inset Formula $R(0)$
3602 \end_inset
3603
3604  by a number slightly above one (such as 1.0001), which is equivalent to
3605  adding noise to the signal.
3606  Also, we can apply a window to the auto-correlation, which is equivalent
3607  to filtering in the frequency domain, reducing sharp resonances.
3608 \end_layout
3609
3610 \begin_layout Standard
3611 The linear prediction model represents each speech sample as a linear combinatio
3612 n of past samples, plus an error signal called the excitation (or residual).
3613 \begin_inset Formula \[
3614 x[n]=\sum_{i=1}^{N}a_{i}x[n-i]+e[n]\]
3615
3616 \end_inset
3617
3618
3619 \end_layout
3620
3621 \begin_layout Standard
3622 In the 
3623 \emph on
3624 z
3625 \emph default
3626 -domain, this can be expressed as
3627 \end_layout
3628
3629 \begin_layout Standard
3630 \begin_inset Formula \[
3631 x(z)=\frac{1}{A(z)}\: e(z)\]
3632
3633 \end_inset
3634
3635
3636 \end_layout
3637
3638 \begin_layout Standard
3639 where 
3640 \begin_inset Formula $A(z)$
3641 \end_inset
3642
3643  is defined as
3644 \end_layout
3645
3646 \begin_layout Standard
3647 \begin_inset Formula \[
3648 A(z)=1-\sum_{i=1}^{N}a_{i}z^{-i}\]
3649
3650 \end_inset
3651
3652
3653 \end_layout
3654
3655 \begin_layout Standard
3656 We usually refer to 
3657 \begin_inset Formula $A(z)$
3658 \end_inset
3659
3660  as the analysis filter and 
3661 \begin_inset Formula $1/A(z)$
3662 \end_inset
3663
3664  as the synthesis filter.
3665  The whole process is called short-term prediction as it predicts the signal
3666  
3667 \begin_inset Formula $x[n]$
3668 \end_inset
3669
3670  using a prediction using only the 
3671 \begin_inset Formula $N$
3672 \end_inset
3673
3674  past samples, where 
3675 \begin_inset Formula $N$
3676 \end_inset
3677
3678  is usually around 10.
3679 \end_layout
3680
3681 \begin_layout Standard
3682 Because LPC coefficients have very little robustness to quantization, they
3683  are converted to Line Spectral Pair
3684 \begin_inset LatexCommand \index{line spectral pair}
3685
3686 \end_inset
3687
3688  (LSP) coefficients which have a much better behaviour with quantization,
3689  one of them being that it's easy to keep the filter stable.
3690  
3691 \end_layout
3692
3693 \begin_layout Standard
3694 \begin_inset Note Comment
3695 status collapsed
3696
3697 \begin_layout Standard
3698 Describe LSP's
3699 \end_layout
3700
3701 \end_inset
3702
3703
3704 \end_layout
3705
3706 \begin_layout Subsection
3707 Pitch Prediction
3708 \begin_inset LatexCommand \index{pitch}
3709
3710 \end_inset
3711
3712
3713 \end_layout
3714
3715 \begin_layout Standard
3716 During voiced segments, the speech signal is periodic, so it is possible
3717  to take advantage of that property by approximating the excitation signal
3718  
3719 \begin_inset Formula $e[n]$
3720 \end_inset
3721
3722  by a gain times the past of the excitation:
3723 \end_layout
3724
3725 \begin_layout Standard
3726 \begin_inset Formula \[
3727 e[n]\simeq p[n]=\beta e[n-T]\]
3728
3729 \end_inset
3730
3731
3732 \end_layout
3733
3734 \begin_layout Standard
3735 where 
3736 \begin_inset Formula $T$
3737 \end_inset
3738
3739  is the pitch period, 
3740 \begin_inset Formula $\beta$
3741 \end_inset
3742
3743  is the pitch gain.
3744  We call that long-term prediction since the excitation is predicted from
3745  
3746 \begin_inset Formula $e[n-T]$
3747 \end_inset
3748
3749  with 
3750 \begin_inset Formula $T\gg N$
3751 \end_inset
3752
3753 .
3754 \end_layout
3755
3756 \begin_layout Subsection
3757 Innovation Codebook
3758 \end_layout
3759
3760 \begin_layout Standard
3761 The final excitation 
3762 \begin_inset Formula $e[n]$
3763 \end_inset
3764
3765  will be the sum of the pitch prediction and an 
3766 \emph on
3767 innovation
3768 \emph default
3769  signal 
3770 \begin_inset Formula $c[n]$
3771 \end_inset
3772
3773  taken from a fixed codebook, hence the name 
3774 \emph on
3775 Code
3776 \emph default
3777  Excited Linear Prediction.
3778  The final excitation is given by:
3779 \end_layout
3780
3781 \begin_layout Standard
3782 \begin_inset Formula \[
3783 e[n]=p[n]+c[n]=\beta e[n-T]+c[n]\]
3784
3785 \end_inset
3786
3787 The quantization of 
3788 \begin_inset Formula $c[n]$
3789 \end_inset
3790
3791  is where most of the bits in a CELP codec are allocated.
3792  It represents the information that couldn't be obtained either from linear
3793  prediction or pitch prediction.
3794  In the 
3795 \emph on
3796 z
3797 \emph default
3798 -domain we can represent the final signal 
3799 \begin_inset Formula $X(z)$
3800 \end_inset
3801
3802  as 
3803 \begin_inset Formula \[
3804 X(z)=\frac{C(z)}{A(z)\left(1-\beta z^{-T}\right)}\]
3805
3806 \end_inset
3807
3808
3809 \end_layout
3810
3811 \begin_layout Subsection
3812 Analysis-by-Synthesis and Error Weighting
3813 \begin_inset LatexCommand \index{error weighting}
3814
3815 \end_inset
3816
3817
3818 \begin_inset LatexCommand \index{analysis-by-synthesis}
3819
3820 \end_inset
3821
3822
3823 \end_layout
3824
3825 \begin_layout Standard
3826 Most (if not all) modern audio codecs attempt to 
3827 \begin_inset Quotes eld
3828 \end_inset
3829
3830 shape
3831 \begin_inset Quotes erd
3832 \end_inset
3833
3834  the noise so that it appears mostly in the frequency regions where the
3835  ear cannot detect it.
3836  For example, the ear is more tolerant to noise in parts of the spectrum
3837  that are louder and 
3838 \emph on
3839 vice versa
3840 \emph default
3841 .
3842  That's why instead of minimizing the simple quadratic error
3843 \begin_inset Formula \[
3844 E=\sum_{n}\left(x[n]-\overline{x}[n]\right)^{2}\]
3845
3846 \end_inset
3847
3848 where 
3849 \begin_inset Formula $\overline{x}[n]$
3850 \end_inset
3851
3852  is the encoder signal, we minimize the error for the perceptually weighted
3853  signal
3854 \begin_inset Formula \[
3855 X_{w}(z)=W(z)X(z)\]
3856
3857 \end_inset
3858
3859 where 
3860 \begin_inset Formula $W(z)$
3861 \end_inset
3862
3863  is the weighting filter, usually of the form
3864 \end_layout
3865
3866 \begin_layout Standard
3867 \begin_inset Formula \begin{equation}
3868 W(z)=\frac{A\left(\frac{z}{\gamma_{1}}\right)}{A\left(\frac{z}{\gamma_{2}}\right)}\label{eq:weighting_filter}\end{equation}
3869
3870 \end_inset
3871
3872
3873 \end_layout
3874
3875 \begin_layout Standard
3876 with control parameters 
3877 \begin_inset Formula $\gamma_{1}>\gamma_{2}$
3878 \end_inset
3879
3880 .
3881  If the noise is white in the perceptually weighted domain, then in the
3882  signal domain its spectral shape will be of the form
3883 \begin_inset Formula \[
3884 A_{noise}(z)=\frac{1}{W(z)}=\frac{A\left(\frac{z}{\gamma_{2}}\right)}{A\left(\frac{z}{\gamma_{1}}\right)}\]
3885
3886 \end_inset
3887
3888
3889 \end_layout
3890
3891 \begin_layout Standard
3892 If a filter 
3893 \begin_inset Formula $A(z)$
3894 \end_inset
3895
3896  has (complex) poles at 
3897 \begin_inset Formula $p_{i}$
3898 \end_inset
3899
3900  in the 
3901 \begin_inset Formula $z$
3902 \end_inset
3903
3904 -plane, the filter 
3905 \begin_inset Formula $A(z/\gamma)$
3906 \end_inset
3907
3908  will have its poles at 
3909 \begin_inset Formula $p'_{i}=\gamma p_{i}$
3910 \end_inset
3911
3912 , making it a flatter version of 
3913 \begin_inset Formula $A(z)$
3914 \end_inset
3915
3916 .
3917 \end_layout
3918
3919 \begin_layout Standard
3920 Analysis-by-synthesis refers to the fact that when trying to find the best
3921  pitch parameters (
3922 \begin_inset Formula $T$
3923 \end_inset
3924
3925
3926 \begin_inset Formula $\beta$
3927 \end_inset
3928
3929 ) and innovation signal 
3930 \begin_inset Formula $c[n]$
3931 \end_inset
3932
3933 , we do not work by making the excitation 
3934 \begin_inset Formula $e[n]$
3935 \end_inset
3936
3937  as close as the original one (which would be simpler), but apply the synthesis
3938  (and weighting) filter and try making 
3939 \begin_inset Formula $X_{w}(z)$
3940 \end_inset
3941
3942  as close to the original as possible.
3943 \end_layout
3944
3945 \begin_layout Standard
3946
3947 \newpage
3948
3949 \end_layout
3950
3951 \begin_layout Section
3952 Speex narrowband mode
3953 \begin_inset LatexCommand \label{sec:Speex-narrowband-mode}
3954
3955 \end_inset
3956
3957
3958 \begin_inset LatexCommand \index{narrowband}
3959
3960 \end_inset
3961
3962
3963 \end_layout
3964
3965 \begin_layout Standard
3966 This section looks at how Speex works for narrowband (
3967 \begin_inset Formula $8\:\mathrm{kHz}$
3968 \end_inset
3969
3970  sampling rate) operation.
3971  The frame size for this mode is 
3972 \begin_inset Formula $20\:\mathrm{ms}$
3973 \end_inset
3974
3975 , corresponding to 160 samples.
3976  Each frame is also subdivided into 4 sub-frames of 40 samples each.
3977 \end_layout
3978
3979 \begin_layout Standard
3980 Also many design decisions were based on the original goals and assumptions:
3981 \end_layout
3982
3983 \begin_layout Itemize
3984 Minimizing the amount of information extracted from past frames (for robustness
3985  to packet loss)
3986 \end_layout
3987
3988 \begin_layout Itemize
3989 Dynamically-selectable codebooks (LSP, pitch and innovation)
3990 \end_layout
3991
3992 \begin_layout Itemize
3993 sub-vector fixed (innovation) codebooks
3994 \end_layout
3995
3996 \begin_layout Subsection
3997 LPC Analysis
3998 \begin_inset LatexCommand \index{linear prediction}
3999
4000 \end_inset
4001
4002
4003 \end_layout
4004
4005 \begin_layout Standard
4006 An LPC analysis is first performed on a (asymetric Hamming) window that
4007  spans all of the current frame and half a frame in advance.
4008  The LPC coefficients are then converted to Line Spectral Pair
4009 \begin_inset LatexCommand \index{line spectral pair}
4010
4011 \end_inset
4012
4013  (LSP), a representation that is more robust to quantization.
4014  The LSP's are considered to be associated to the 
4015 \begin_inset Formula $4^{th}$
4016 \end_inset
4017
4018  sub-frames and the LSP's associated to the first 3 sub-frames are linearly
4019  interpolated using the current and previous LSP's.
4020 \end_layout
4021
4022 \begin_layout Standard
4023 The LSP's are encoded using 30 bits for higher quality modes and 18 bits
4024  for lower quality, through the use of a multi-stage split-vector quantizer.
4025  For the lower quality modes, the 10 coefficients are first quantized with
4026  6 bits and the error is then divided in two 5-coefficient sub-vectors.
4027  Each of them is quantized with 6 bits, for a total of 18 bits.
4028  For the higher quality modes, the remaining error on both sub-vectors is
4029  further quantized with 6 bits each, for a total of 30 bits.
4030 \end_layout
4031
4032 \begin_layout Standard
4033 The perceptual weighting filter 
4034 \begin_inset Formula $W(z)$
4035 \end_inset
4036
4037  used by Speex is derived from the LPC filter 
4038 \begin_inset Formula $A(z)$
4039 \end_inset
4040
4041  and corresponds to the one described by eq.
4042  
4043 \begin_inset LatexCommand \ref{eq:weighting_filter}
4044
4045 \end_inset
4046
4047  with 
4048 \begin_inset Formula $\gamma_{1}=0.9$
4049 \end_inset
4050
4051  and 
4052 \begin_inset Formula $\gamma_{2}=0.6$
4053 \end_inset
4054
4055 .
4056  We can use the unquantized 
4057 \begin_inset Formula $A(z)$
4058 \end_inset
4059
4060  filter since the weighting filter is only used in the encoder.
4061 \end_layout
4062
4063 \begin_layout Subsection
4064 Pitch Prediction (adaptive codebook)
4065 \begin_inset LatexCommand \index{pitch}
4066
4067 \end_inset
4068
4069
4070 \end_layout
4071
4072 \begin_layout Standard
4073 Speex uses a 3-tap prediction for pitch.
4074  That is, the pitch prediction signal 
4075 \begin_inset Formula $p[n]$
4076 \end_inset
4077
4078  is obtained by the past of the excitation by:
4079 \begin_inset Formula \[
4080 p[n]=\beta_{0}e[n-T-1]+\beta_{1}e[n-T]+\beta_{2}e[n-T+1]\]
4081
4082 \end_inset
4083
4084
4085 \end_layout
4086
4087 \begin_layout Standard
4088 where 
4089 \begin_inset Formula $T$
4090 \end_inset
4091
4092  is the pitch period and the 
4093 \begin_inset Formula $\beta_{i}$
4094 \end_inset
4095
4096  are the prediction (filter) taps.
4097  It is worth noting that when the pitch is smaller than the sub-frame size,
4098  we repeat the excitation at a period 
4099 \begin_inset Formula $T$
4100 \end_inset
4101
4102 .
4103  For example, when 
4104 \begin_inset Formula $n-T+1$
4105 \end_inset
4106
4107 , we use 
4108 \begin_inset Formula $n-2T+1$
4109 \end_inset
4110
4111  instead.
4112  The period and quantized gains are determined in closed loop (analysis-by-synth
4113 esis).
4114  In most modes, the pitch period is encoded with 7 bits in the 
4115 \begin_inset Formula $\left[17,144\right]$
4116 \end_inset
4117
4118  range and the 
4119 \begin_inset Formula $\beta_{i}$
4120 \end_inset
4121
4122  coefficients are vector-quantized using 7 bits (15 kbps narrowband and
4123  above) at higher bit-rates and 5 bits at lower bit-rates (11 kbps narrowband
4124  and below).
4125 \end_layout
4126
4127 \begin_layout Subsection
4128 Innovation Codebook
4129 \end_layout
4130
4131 \begin_layout Standard
4132 In Speex, the innovation signal is quantized using sub-vector shape-only
4133  vector quantization (VQ).
4134  That means that the innovation signal is divided in sub-vectors (of size
4135  5 to 20) and quantized using a codebook that represents both the shape
4136  and the gain at the same time.
4137  This saves many bits that would otherwise be allocated for a separate gain
4138  at the price of a slight increase in complexity.
4139  
4140 \end_layout
4141
4142 \begin_layout Subsection
4143 Bit allocation
4144 \end_layout
4145
4146 \begin_layout Standard
4147 There are 7 different narrowband bit-rates defined for Speex, ranging from
4148  250 bps to 24.6 kbps, although the modes below 5.9 kbps should not be used
4149  for speech.
4150  The bit-allocation for each mode is detailed in table 
4151 \begin_inset LatexCommand \ref{cap:bits-narrowband}
4152
4153 \end_inset
4154
4155 .
4156  Each frame starts with the mode ID encoded with 4 bits which allows a range
4157  from 0 to 15, though only the first 7 values are used (the others are reserved).
4158  The parameters are listed in the table in the order they are packed in
4159  the bit-stream.
4160  All frame-based parameters are packed before sub-frame parameters.
4161  The parameters for a certain sub-frame are all packed before the following
4162  sub-frame is packed.
4163  Note that the 
4164 \begin_inset Quotes eld
4165 \end_inset
4166
4167 OL
4168 \begin_inset Quotes erd
4169 \end_inset
4170
4171  in the parameter description means that the parameter is an open loop estimatio
4172 n based on the whole frame.
4173 \end_layout
4174
4175 \begin_layout Standard
4176 \begin_inset Float table
4177 placement h
4178 wide true
4179 sideways false
4180 status open
4181
4182 \begin_layout Standard
4183 \begin_inset Tabular
4184 <lyxtabular version="3" rows="12" columns="11">
4185 <features>
4186 <column alignment="center" valignment="top" leftline="true" width="0pt">
4187 <column alignment="center" valignment="top" leftline="true" width="0pt">
4188 <column alignment="center" valignment="top" leftline="true" width="0pt">
4189 <column alignment="center" valignment="top" leftline="true" width="0pt">
4190 <column alignment="center" valignment="top" leftline="true" width="0pt">
4191 <column alignment="center" valignment="top" leftline="true" width="0pt">
4192 <column alignment="center" valignment="top" leftline="true" width="0pt">
4193 <column alignment="center" valignment="top" leftline="true" width="0pt">
4194 <column alignment="center" valignment="top" leftline="true" width="0pt">
4195 <column alignment="center" valignment="top" leftline="true" width="0pt">
4196 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
4197 <row topline="true" bottomline="true">
4198 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4199 \begin_inset Text
4200
4201 \begin_layout Standard
4202 Parameter
4203 \end_layout
4204
4205 \end_inset
4206 </cell>
4207 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4208 \begin_inset Text
4209
4210 \begin_layout Standard
4211 Update rate
4212 \end_layout
4213
4214 \end_inset
4215 </cell>
4216 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4217 \begin_inset Text
4218
4219 \begin_layout Standard
4220 0
4221 \end_layout
4222
4223 \end_inset
4224 </cell>
4225 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4226 \begin_inset Text
4227
4228 \begin_layout Standard
4229 1
4230 \end_layout
4231
4232 \end_inset
4233 </cell>
4234 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4235 \begin_inset Text
4236
4237 \begin_layout Standard
4238 2
4239 \end_layout
4240
4241 \end_inset
4242 </cell>
4243 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4244 \begin_inset Text
4245
4246 \begin_layout Standard
4247 3
4248 \end_layout
4249
4250 \end_inset
4251 </cell>
4252 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4253 \begin_inset Text
4254
4255 \begin_layout Standard
4256 4
4257 \end_layout
4258
4259 \end_inset
4260 </cell>
4261 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4262 \begin_inset Text
4263
4264 \begin_layout Standard
4265 5
4266 \end_layout
4267
4268 \end_inset
4269 </cell>
4270 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
4271 \begin_inset Text
4272
4273 \begin_layout Standard
4274 6
4275 \end_layout
4276
4277 \end_inset
4278 </cell>
4279 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
4280 \begin_inset Text
4281
4282 \begin_layout Standard
4283 7
4284 \end_layout
4285
4286 \end_inset
4287 </cell>
4288 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
4289 \begin_inset Text
4290
4291 \begin_layout Standard
4292 8
4293 \end_layout
4294
4295 \end_inset
4296 </cell>
4297 </row>
4298 <row topline="true">
4299 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4300 \begin_inset Text
4301
4302 \begin_layout Standard
4303 Wideband bit
4304 \end_layout
4305
4306 \end_inset
4307 </cell>
4308 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4309 \begin_inset Text
4310
4311 \begin_layout Standard
4312 frame
4313 \end_layout
4314
4315 \end_inset
4316 </cell>
4317 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4318 \begin_inset Text
4319
4320 \begin_layout Standard
4321 1
4322 \end_layout
4323
4324 \end_inset
4325 </cell>
4326 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4327 \begin_inset Text
4328
4329 \begin_layout Standard
4330 1
4331 \end_layout
4332
4333 \end_inset
4334 </cell>
4335 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4336 \begin_inset Text
4337
4338 \begin_layout Standard
4339 1
4340 \end_layout
4341
4342 \end_inset
4343 </cell>
4344 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4345 \begin_inset Text
4346
4347 \begin_layout Standard
4348 1
4349 \end_layout
4350
4351 \end_inset
4352 </cell>
4353 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4354 \begin_inset Text
4355
4356 \begin_layout Standard
4357 1
4358 \end_layout
4359
4360 \end_inset
4361 </cell>
4362 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4363 \begin_inset Text
4364
4365 \begin_layout Standard
4366 1
4367 \end_layout
4368
4369 \end_inset
4370 </cell>
4371 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
4372 \begin_inset Text
4373
4374 \begin_layout Standard
4375 1
4376 \end_layout
4377
4378 \end_inset
4379 </cell>
4380 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
4381 \begin_inset Text
4382
4383 \begin_layout Standard
4384 1
4385 \end_layout
4386
4387 \end_inset
4388 </cell>
4389 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
4390 \begin_inset Text
4391
4392 \begin_layout Standard
4393 1
4394 \end_layout
4395
4396 \end_inset
4397 </cell>
4398 </row>
4399 <row topline="true">
4400 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4401 \begin_inset Text
4402
4403 \begin_layout Standard
4404 Mode ID
4405 \end_layout
4406
4407 \end_inset
4408 </cell>
4409 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4410 \begin_inset Text
4411
4412 \begin_layout Standard
4413 frame
4414 \end_layout
4415
4416 \end_inset
4417 </cell>
4418 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4419 \begin_inset Text
4420
4421 \begin_layout Standard
4422 4
4423 \end_layout
4424
4425 \end_inset
4426 </cell>
4427 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4428 \begin_inset Text
4429
4430 \begin_layout Standard
4431 4
4432 \end_layout
4433
4434 \end_inset
4435 </cell>
4436 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4437 \begin_inset Text
4438
4439 \begin_layout Standard
4440 4
4441 \end_layout
4442
4443 \end_inset
4444 </cell>
4445 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4446 \begin_inset Text
4447
4448 \begin_layout Standard
4449 4
4450 \end_layout
4451
4452 \end_inset
4453 </cell>
4454 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4455 \begin_inset Text
4456
4457 \begin_layout Standard
4458 4
4459 \end_layout
4460
4461 \end_inset
4462 </cell>
4463 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4464 \begin_inset Text
4465
4466 \begin_layout Standard
4467 4
4468 \end_layout
4469
4470 \end_inset
4471 </cell>
4472 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
4473 \begin_inset Text
4474
4475 \begin_layout Standard
4476 4
4477 \end_layout
4478
4479 \end_inset
4480 </cell>
4481 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
4482 \begin_inset Text
4483
4484 \begin_layout Standard
4485 4
4486 \end_layout
4487
4488 \end_inset
4489 </cell>
4490 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
4491 \begin_inset Text
4492
4493 \begin_layout Standard
4494 4
4495 \end_layout
4496
4497 \end_inset
4498 </cell>
4499 </row>
4500 <row topline="true">
4501 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4502 \begin_inset Text
4503
4504 \begin_layout Standard
4505 LSP
4506 \end_layout
4507
4508 \end_inset
4509 </cell>
4510 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4511 \begin_inset Text
4512
4513 \begin_layout Standard
4514 frame
4515 \end_layout
4516
4517 \end_inset
4518 </cell>
4519 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4520 \begin_inset Text
4521
4522 \begin_layout Standard
4523 0
4524 \end_layout
4525
4526 \end_inset
4527 </cell>
4528 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4529 \begin_inset Text
4530
4531 \begin_layout Standard
4532 18
4533 \end_layout
4534
4535 \end_inset
4536 </cell>
4537 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4538 \begin_inset Text
4539
4540 \begin_layout Standard
4541 18
4542 \end_layout
4543
4544 \end_inset
4545 </cell>
4546 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4547 \begin_inset Text
4548
4549 \begin_layout Standard
4550 18
4551 \end_layout
4552
4553 \end_inset
4554 </cell>
4555 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4556 \begin_inset Text
4557
4558 \begin_layout Standard
4559 18
4560 \end_layout
4561
4562 \end_inset
4563 </cell>
4564 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4565 \begin_inset Text
4566
4567 \begin_layout Standard
4568 30
4569 \end_layout
4570
4571 \end_inset
4572 </cell>
4573 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
4574 \begin_inset Text
4575
4576 \begin_layout Standard
4577 30
4578 \end_layout
4579
4580 \end_inset
4581 </cell>
4582 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
4583 \begin_inset Text
4584
4585 \begin_layout Standard
4586 30
4587 \end_layout
4588
4589 \end_inset
4590 </cell>
4591 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
4592 \begin_inset Text
4593
4594 \begin_layout Standard
4595 18
4596 \end_layout
4597
4598 \end_inset
4599 </cell>
4600 </row>
4601 <row topline="true">
4602 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4603 \begin_inset Text
4604
4605 \begin_layout Standard
4606 OL pitch
4607 \end_layout
4608
4609 \end_inset
4610 </cell>
4611 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4612 \begin_inset Text
4613
4614 \begin_layout Standard
4615 frame
4616 \end_layout
4617
4618 \end_inset
4619 </cell>
4620 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4621 \begin_inset Text
4622
4623 \begin_layout Standard
4624 0
4625 \end_layout
4626
4627 \end_inset
4628 </cell>
4629 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4630 \begin_inset Text
4631
4632 \begin_layout Standard
4633 7
4634 \end_layout
4635
4636 \end_inset
4637 </cell>
4638 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4639 \begin_inset Text
4640
4641 \begin_layout Standard
4642 7
4643 \end_layout
4644
4645 \end_inset
4646 </cell>
4647 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4648 \begin_inset Text
4649
4650 \begin_layout Standard
4651 0
4652 \end_layout
4653
4654 \end_inset
4655 </cell>
4656 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4657 \begin_inset Text
4658
4659 \begin_layout Standard
4660 0
4661 \end_layout
4662
4663 \end_inset
4664 </cell>
4665 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4666 \begin_inset Text
4667
4668 \begin_layout Standard
4669 0
4670 \end_layout
4671
4672 \end_inset
4673 </cell>
4674 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
4675 \begin_inset Text
4676
4677 \begin_layout Standard
4678 0
4679 \end_layout
4680
4681 \end_inset
4682 </cell>
4683 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
4684 \begin_inset Text
4685
4686 \begin_layout Standard
4687 0
4688 \end_layout
4689
4690 \end_inset
4691 </cell>
4692 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
4693 \begin_inset Text
4694
4695 \begin_layout Standard
4696 7
4697 \end_layout
4698
4699 \end_inset
4700 </cell>
4701 </row>
4702 <row topline="true">
4703 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4704 \begin_inset Text
4705
4706 \begin_layout Standard
4707 OL pitch gain
4708 \end_layout
4709
4710 \end_inset
4711 </cell>
4712 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4713 \begin_inset Text
4714
4715 \begin_layout Standard
4716 frame
4717 \end_layout
4718
4719 \end_inset
4720 </cell>
4721 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4722 \begin_inset Text
4723
4724 \begin_layout Standard
4725 0
4726 \end_layout
4727
4728 \end_inset
4729 </cell>
4730 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4731 \begin_inset Text
4732
4733 \begin_layout Standard
4734 4
4735 \end_layout
4736
4737 \end_inset
4738 </cell>
4739 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4740 \begin_inset Text
4741
4742 \begin_layout Standard
4743 0
4744 \end_layout
4745
4746 \end_inset
4747 </cell>
4748 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4749 \begin_inset Text
4750
4751 \begin_layout Standard
4752 0
4753 \end_layout
4754
4755 \end_inset
4756 </cell>
4757 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4758 \begin_inset Text
4759
4760 \begin_layout Standard
4761 0
4762 \end_layout
4763
4764 \end_inset
4765 </cell>
4766 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4767 \begin_inset Text
4768
4769 \begin_layout Standard
4770 0
4771 \end_layout
4772
4773 \end_inset
4774 </cell>
4775 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
4776 \begin_inset Text
4777
4778 \begin_layout Standard
4779 0
4780 \end_layout
4781
4782 \end_inset
4783 </cell>
4784 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
4785 \begin_inset Text
4786
4787 \begin_layout Standard
4788 0
4789 \end_layout
4790
4791 \end_inset
4792 </cell>
4793 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
4794 \begin_inset Text
4795
4796 \begin_layout Standard
4797 4
4798 \end_layout
4799
4800 \end_inset
4801 </cell>
4802 </row>
4803 <row topline="true">
4804 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4805 \begin_inset Text
4806
4807 \begin_layout Standard
4808 OL Exc gain
4809 \end_layout
4810
4811 \end_inset
4812 </cell>
4813 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4814 \begin_inset Text
4815
4816 \begin_layout Standard
4817 frame
4818 \end_layout
4819
4820 \end_inset
4821 </cell>
4822 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4823 \begin_inset Text
4824
4825 \begin_layout Standard
4826 0
4827 \end_layout
4828
4829 \end_inset
4830 </cell>
4831 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4832 \begin_inset Text
4833
4834 \begin_layout Standard
4835 5
4836 \end_layout
4837
4838 \end_inset
4839 </cell>
4840 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4841 \begin_inset Text
4842
4843 \begin_layout Standard
4844 5
4845 \end_layout
4846
4847 \end_inset
4848 </cell>
4849 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4850 \begin_inset Text
4851
4852 \begin_layout Standard
4853 5
4854 \end_layout
4855
4856 \end_inset
4857 </cell>
4858 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4859 \begin_inset Text
4860
4861 \begin_layout Standard
4862 5
4863 \end_layout
4864
4865 \end_inset
4866 </cell>
4867 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4868 \begin_inset Text
4869
4870 \begin_layout Standard
4871 5
4872 \end_layout
4873
4874 \end_inset
4875 </cell>
4876 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
4877 \begin_inset Text
4878
4879 \begin_layout Standard
4880 5
4881 \end_layout
4882
4883 \end_inset
4884 </cell>
4885 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
4886 \begin_inset Text
4887
4888 \begin_layout Standard
4889 5
4890 \end_layout
4891
4892 \end_inset
4893 </cell>
4894 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
4895 \begin_inset Text
4896
4897 \begin_layout Standard
4898 5
4899 \end_layout
4900
4901 \end_inset
4902 </cell>
4903 </row>
4904 <row topline="true">
4905 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4906 \begin_inset Text
4907
4908 \begin_layout Standard
4909 Fine pitch
4910 \end_layout
4911
4912 \end_inset
4913 </cell>
4914 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4915 \begin_inset Text
4916
4917 \begin_layout Standard
4918 sub-frame
4919 \end_layout
4920
4921 \end_inset
4922 </cell>
4923 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4924 \begin_inset Text
4925
4926 \begin_layout Standard
4927 0
4928 \end_layout
4929
4930 \end_inset
4931 </cell>
4932 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4933 \begin_inset Text
4934
4935 \begin_layout Standard
4936 0
4937 \end_layout
4938
4939 \end_inset
4940 </cell>
4941 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4942 \begin_inset Text
4943
4944 \begin_layout Standard
4945 0
4946 \end_layout
4947
4948 \end_inset
4949 </cell>
4950 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4951 \begin_inset Text
4952
4953 \begin_layout Standard
4954 7
4955 \end_layout
4956
4957 \end_inset
4958 </cell>
4959 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4960 \begin_inset Text
4961
4962 \begin_layout Standard
4963 7
4964 \end_layout
4965
4966 \end_inset
4967 </cell>
4968 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
4969 \begin_inset Text
4970
4971 \begin_layout Standard
4972 7
4973 \end_layout
4974
4975 \end_inset
4976 </cell>
4977 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
4978 \begin_inset Text
4979
4980 \begin_layout Standard
4981 7
4982 \end_layout
4983
4984 \end_inset
4985 </cell>
4986 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
4987 \begin_inset Text
4988
4989 \begin_layout Standard
4990 7
4991 \end_layout
4992
4993 \end_inset
4994 </cell>
4995 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
4996 \begin_inset Text
4997
4998 \begin_layout Standard
4999 0
5000 \end_layout
5001
5002 \end_inset
5003 </cell>
5004 </row>
5005 <row topline="true">
5006 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
5007 \begin_inset Text
5008
5009 \begin_layout Standard
5010 Pitch gain
5011 \end_layout
5012
5013 \end_inset
5014 </cell>
5015 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
5016 \begin_inset Text
5017
5018 \begin_layout Standard
5019 sub-frame
5020 \end_layout
5021
5022 \end_inset
5023 </cell>
5024 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
5025 \begin_inset Text
5026
5027 \begin_layout Standard
5028 0
5029 \end_layout
5030
5031 \end_inset
5032 </cell>
5033 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
5034 \begin_inset Text
5035
5036 \begin_layout Standard
5037 0
5038 \end_layout
5039
5040 \end_inset
5041 </cell>
5042 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
5043 \begin_inset Text
5044
5045 \begin_layout Standard
5046 5
5047 \end_layout
5048
5049 \end_inset
5050 </cell>
5051 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
5052 \begin_inset Text
5053
5054 \begin_layout Standard
5055 5
5056 \end_layout
5057
5058 \end_inset
5059 </cell>
5060 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
5061 \begin_inset Text
5062
5063 \begin_layout Standard
5064 5
5065 \end_layout
5066
5067 \end_inset
5068 </cell>
5069 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
5070 \begin_inset Text
5071
5072 \begin_layout Standard
5073 7
5074 \end_layout
5075
5076 \end_inset
5077 </cell>
5078 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
5079 \begin_inset Text
5080
5081 \begin_layout Standard
5082 7
5083 \end_layout
5084
5085 \end_inset
5086 </cell>
5087 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
5088 \begin_inset Text
5089
5090 \begin_layout Standard
5091 7
5092 \end_layout
5093
5094 \end_inset
5095 </cell>
5096 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
5097 \begin_inset Text
5098
5099 \begin_layout Standard
5100 0
5101 \end_layout
5102
5103 \end_inset
5104 </cell>
5105 </row>
5106 <row topline="true">
5107 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
5108 \begin_inset Text
5109
5110 \begin_layout Standard
5111 Innovation gain
5112 \end_layout
5113
5114 \end_inset
5115 </cell>
5116 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
5117 \begin_inset Text
5118
5119 \begin_layout Standard
5120 sub-frame
5121 \end_layout
5122
5123 \end_inset
5124 </cell>
5125 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
5126 \begin_inset Text
5127
5128 \begin_layout Standard
5129 0
5130 \end_layout
5131
5132 \end_inset
5133 </cell>
5134 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
5135 \begin_inset Text
5136
5137 \begin_layout Standard
5138 1
5139 \end_layout
5140
5141 \end_inset
5142 </cell>
5143 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
5144 \begin_inset Text
5145
5146 \begin_layout Standard
5147 0
5148 \end_layout
5149
5150 \end_inset
5151 </cell>
5152 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
5153 \begin_inset Text
5154
5155 \begin_layout Standard
5156 1
5157 \end_layout
5158
5159 \end_inset
5160 </cell>
5161 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
5162 \begin_inset Text
5163
5164 \begin_layout Standard
5165 1
5166 \end_layout
5167
5168 \end_inset
5169 </cell>
5170 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
5171 \begin_inset Text
5172
5173 \begin_layout Standard
5174 3
5175 \end_layout
5176
5177 \end_inset
5178 </cell>
5179 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
5180 \begin_inset Text
5181
5182 \begin_layout Standard
5183 3
5184 \end_layout
5185
5186 \end_inset
5187 </cell>
5188 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
5189 \begin_inset Text
5190
5191 \begin_layout Standard
5192 3
5193 \end_layout
5194
5195 \end_inset
5196 </cell>
5197 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
5198 \begin_inset Text
5199
5200 \begin_layout Standard
5201 0
5202 \end_layout
5203
5204 \end_inset
5205 </cell>
5206 </row>
5207 <row topline="true" bottomline="true">
5208 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
5209 \begin_inset Text
5210
5211 \begin_layout Standard
5212 Innovation VQ
5213 \end_layout
5214
5215 \end_inset
5216 </cell>
5217 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
5218 \begin_inset Text
5219
5220 \begin_layout Standard
5221 sub-frame
5222 \end_layout
5223
5224 \end_inset
5225 </cell>
5226 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
5227 \begin_inset Text
5228
5229 \begin_layout Standard
5230 0
5231 \end_layout
5232
5233 \end_inset
5234 </cell>
5235 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
5236 \begin_inset Text
5237
5238 \begin_layout Standard
5239 0
5240 \end_layout
5241
5242 \end_inset
5243 </cell>
5244 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
5245 \begin_inset Text
5246
5247 \begin_layout Standard
5248 16
5249 \end_layout
5250
5251 \end_inset
5252 </cell>
5253 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
5254 \begin_inset Text
5255
5256 \begin_layout Standard
5257 20
5258 \end_layout
5259
5260 \end_inset
5261 </cell>
5262 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
5263 \begin_inset Text
5264
5265 \begin_layout Standard
5266 35
5267 \end_layout
5268
5269 \end_inset
5270 </cell>
5271 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
5272 \begin_inset Text
5273
5274 \begin_layout Standard
5275 48
5276 \end_layout
5277
5278 \end_inset
5279 </cell>
5280 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
5281 \begin_inset Text
5282
5283 \begin_layout Standard
5284 64
5285 \end_layout
5286
5287 \end_inset
5288 </cell>
5289 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
5290 \begin_inset Text
5291
5292 \begin_layout Standard
5293 96
5294 \end_layout
5295
5296 \end_inset
5297 </cell>
5298 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
5299 \begin_inset Text
5300
5301 \begin_layout Standard
5302 10
5303 \end_layout
5304
5305 \end_inset
5306 </cell>
5307 </row>
5308 <row topline="true" bottomline="true">
5309 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
5310 \begin_inset Text
5311
5312 \begin_layout Standard
5313 Total
5314 \end_layout
5315
5316 \end_inset
5317 </cell>
5318 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
5319 \begin_inset Text
5320
5321 \begin_layout Standard
5322 frame
5323 \end_layout
5324
5325 \end_inset
5326 </cell>
5327 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
5328 \begin_inset Text
5329
5330 \begin_layout Standard
5331 5
5332 \end_layout
5333
5334 \end_inset
5335 </cell>
5336 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
5337 \begin_inset Text
5338
5339 \begin_layout Standard
5340 43
5341 \end_layout
5342
5343 \end_inset
5344 </cell>
5345 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
5346 \begin_inset Text
5347
5348 \begin_layout Standard
5349 119
5350 \end_layout
5351
5352 \end_inset
5353 </cell>
5354 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
5355 \begin_inset Text
5356
5357 \begin_layout Standard
5358 160
5359 \end_layout
5360
5361 \end_inset
5362 </cell>
5363 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
5364 \begin_inset Text
5365
5366 \begin_layout Standard
5367 220
5368 \end_layout
5369
5370 \end_inset
5371 </cell>
5372 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
5373 \begin_inset Text
5374
5375 \begin_layout Standard
5376 300
5377 \end_layout
5378
5379 \end_inset
5380 </cell>
5381 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
5382 \begin_inset Text
5383
5384 \begin_layout Standard
5385 364
5386 \end_layout
5387
5388 \end_inset
5389 </cell>
5390 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
5391 \begin_inset Text
5392
5393 \begin_layout Standard
5394 492
5395 \end_layout
5396
5397 \end_inset
5398 </cell>
5399 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
5400 \begin_inset Text
5401
5402 \begin_layout Standard
5403 79
5404 \end_layout
5405
5406 \end_inset
5407 </cell>
5408 </row>
5409 </lyxtabular>
5410
5411 \end_inset
5412
5413
5414 \end_layout
5415
5416 \begin_layout Caption
5417 Bit allocation for narrowband modes
5418 \begin_inset LatexCommand \label{cap:bits-narrowband}
5419
5420 \end_inset
5421
5422
5423 \end_layout
5424
5425 \end_inset
5426
5427
5428 \end_layout
5429
5430 \begin_layout Standard
5431 So far, no MOS (Mean Opinion Score
5432 \begin_inset LatexCommand \index{mean opinion score}
5433
5434 \end_inset
5435
5436 ) subjective evaluation has been performed for Speex.
5437  In order to give an idea of the quality achivable with it, table 
5438 \begin_inset LatexCommand \ref{cap:quality_vs_bps}
5439
5440 \end_inset
5441
5442  presents my own subjective opinion on it.
5443  It sould be noted that different people will perceive the quality differently
5444  and that the person that designed the codec often has a bias (one way or
5445  another) when it comes to subjective evaluation.
5446  Last thing, it should be noted that for most codecs (including Speex) encoding
5447  quality sometimes varies depending on the input.
5448  Note that the complexity is only approximate (within 0.5 mflops and using
5449  the lowest complexity setting).
5450  Decoding requires approximately 0.5 mflops
5451 \begin_inset LatexCommand \index{complexity}
5452
5453 \end_inset
5454
5455  in most modes (1 mflops with perceptual enhancement).
5456 \end_layout
5457
5458 \begin_layout Standard
5459 \begin_inset Float table
5460 placement h
5461 wide true
5462 sideways false
5463 status open
5464
5465 \begin_layout Standard
5466 \begin_inset Tabular
5467 <lyxtabular version="3" rows="17" columns="4">
5468 <features>
5469 <column alignment="center" valignment="top" leftline="true" width="0pt">
5470 <column alignment="center" valignment="top" leftline="true" width="0pt">
5471 <column alignment="center" valignment="top" leftline="true" width="0pt">
5472 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
5473 <row topline="true" bottomline="true">
5474 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
5475 \begin_inset Text
5476
5477 \begin_layout Standard
5478 Mode
5479 \end_layout
5480
5481 \end_inset
5482 </cell>
5483 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
5484 \begin_inset Text