home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Tools / Languages / Python 1.1 / Doc / libaudioop.tex < prev    next >
LaTeX Document  |  1994-08-08  |  9.8 KB  |  [TEXT/R*ch]

open in: MacOS 8.1     |     Win98     |     DOS

view JSON data     |     view as text

This file was processed as: LaTeX Document (document/latex).

You can browse this item here: libaudioop.tex

ConfidenceProgramDetectionMatch TypeSupport
100% dexvert LaTeX Document (document/latex) magic Supported
1% dexvert Text File (text/txt) fallback Supported
100% file LaTeX document text default
99% file LaTeX document, ASCII text, with CR line terminators default
100% checkBytes Printable ASCII default
100% perlTextCheck Likely Text (Perl) default
100% siegfried fmt/281 LaTeX (Subdocument) default
100% detectItEasy Format: plain text[CR] default (weak)


id metadata
keyvalue
macFileType[TEXT]
macFileCreator[R*ch]



hex view
+--------+-------------------------+-------------------------+--------+--------+
|00000000| 5c 73 65 63 74 69 6f 6e | 7b 42 75 69 6c 74 2d 69 |\section|{Built-i|
|00000010| 6e 20 6d 6f 64 75 6c 65 | 20 5c 73 65 63 74 63 6f |n module| \sectco|
|00000020| 64 65 7b 61 75 64 69 6f | 6f 70 7d 7d 0d 5c 62 69 |de{audio|op}}.\bi|
|00000030| 6d 6f 64 69 6e 64 65 78 | 7b 61 75 64 69 6f 6f 70 |modindex|{audioop|
|00000040| 7d 0d 0d 54 68 65 20 61 | 75 64 69 6f 6f 70 20 6d |}..The a|udioop m|
|00000050| 6f 64 75 6c 65 20 63 6f | 6e 74 61 69 6e 73 20 73 |odule co|ntains s|
|00000060| 6f 6d 65 20 75 73 65 66 | 75 6c 20 6f 70 65 72 61 |ome usef|ul opera|
|00000070| 74 69 6f 6e 73 20 6f 6e | 20 73 6f 75 6e 64 20 66 |tions on| sound f|
|00000080| 72 61 67 6d 65 6e 74 73 | 2e 0d 49 74 20 6f 70 65 |ragments|..It ope|
|00000090| 72 61 74 65 73 20 6f 6e | 20 73 6f 75 6e 64 20 66 |rates on| sound f|
|000000a0| 72 61 67 6d 65 6e 74 73 | 20 63 6f 6e 73 69 73 74 |ragments| consist|
|000000b0| 69 6e 67 20 6f 66 20 73 | 69 67 6e 65 64 20 69 6e |ing of s|igned in|
|000000c0| 74 65 67 65 72 20 73 61 | 6d 70 6c 65 73 20 6f 66 |teger sa|mples of|
|000000d0| 0d 38 2c 20 31 36 20 6f | 72 20 33 32 20 62 69 74 |.8, 16 o|r 32 bit|
|000000e0| 73 20 77 69 64 65 2c 20 | 73 74 6f 72 65 64 20 69 |s wide, |stored i|
|000000f0| 6e 20 50 79 74 68 6f 6e | 20 73 74 72 69 6e 67 73 |n Python| strings|
|00000100| 2e 20 20 54 68 69 73 20 | 69 73 20 74 68 65 20 73 |. This |is the s|
|00000110| 61 6d 65 0d 66 6f 72 6d | 61 74 20 61 73 20 75 73 |ame.form|at as us|
|00000120| 65 64 20 62 79 20 74 68 | 65 20 5c 63 6f 64 65 7b |ed by th|e \code{|
|00000130| 61 6c 7d 20 61 6e 64 20 | 5c 63 6f 64 65 7b 73 75 |al} and |\code{su|
|00000140| 6e 61 75 64 69 6f 64 65 | 76 7d 20 6d 6f 64 75 6c |naudiode|v} modul|
|00000150| 65 73 2e 20 20 41 6c 6c | 0d 73 63 61 6c 61 72 20 |es. All|.scalar |
|00000160| 69 74 65 6d 73 20 61 72 | 65 20 69 6e 74 65 67 65 |items ar|e intege|
|00000170| 72 73 2c 20 75 6e 6c 65 | 73 73 20 73 70 65 63 69 |rs, unle|ss speci|
|00000180| 66 69 65 64 20 6f 74 68 | 65 72 77 69 73 65 2e 0d |fied oth|erwise..|
|00000190| 0d 41 20 66 65 77 20 6f | 66 20 74 68 65 20 6d 6f |.A few o|f the mo|
|000001a0| 72 65 20 63 6f 6d 70 6c | 69 63 61 74 65 64 20 6f |re compl|icated o|
|000001b0| 70 65 72 61 74 69 6f 6e | 73 20 6f 6e 6c 79 20 74 |peration|s only t|
|000001c0| 61 6b 65 20 31 36 2d 62 | 69 74 20 73 61 6d 70 6c |ake 16-b|it sampl|
|000001d0| 65 73 2c 0d 6f 74 68 65 | 72 77 69 73 65 20 74 68 |es,.othe|rwise th|
|000001e0| 65 20 73 61 6d 70 6c 65 | 20 73 69 7a 65 20 28 69 |e sample| size (i|
|000001f0| 6e 20 62 79 74 65 73 29 | 20 69 73 20 61 6c 77 61 |n bytes)| is alwa|
|00000200| 79 73 20 61 20 70 61 72 | 61 6d 65 74 65 72 20 6f |ys a par|ameter o|
|00000210| 66 20 74 68 65 20 6f 70 | 65 72 61 74 69 6f 6e 2e |f the op|eration.|
|00000220| 0d 0d 54 68 65 20 6d 6f | 64 75 6c 65 20 64 65 66 |..The mo|dule def|
|00000230| 69 6e 65 73 20 74 68 65 | 20 66 6f 6c 6c 6f 77 69 |ines the| followi|
|00000240| 6e 67 20 76 61 72 69 61 | 62 6c 65 73 20 61 6e 64 |ng varia|bles and|
|00000250| 20 66 75 6e 63 74 69 6f | 6e 73 3a 0d 0d 5c 72 65 | functio|ns:..\re|
|00000260| 6e 65 77 63 6f 6d 6d 61 | 6e 64 7b 5c 69 6e 64 65 |newcomma|nd{\inde|
|00000270| 78 73 75 62 69 74 65 6d | 7d 7b 28 69 6e 20 6d 6f |xsubitem|}{(in mo|
|00000280| 64 75 6c 65 20 61 75 64 | 69 6f 6f 70 29 7d 0d 5c |dule aud|ioop)}.\|
|00000290| 62 65 67 69 6e 7b 65 78 | 63 64 65 73 63 7d 7b 65 |begin{ex|cdesc}{e|
|000002a0| 72 72 6f 72 7d 0d 54 68 | 69 73 20 65 78 63 65 70 |rror}.Th|is excep|
|000002b0| 74 69 6f 6e 20 69 73 20 | 72 61 69 73 65 64 20 6f |tion is |raised o|
|000002c0| 6e 20 61 6c 6c 20 65 72 | 72 6f 72 73 2c 20 73 75 |n all er|rors, su|
|000002d0| 63 68 20 61 73 20 75 6e | 6b 6e 6f 77 6e 20 6e 75 |ch as un|known nu|
|000002e0| 6d 62 65 72 20 6f 66 20 | 62 79 74 65 73 0d 70 65 |mber of |bytes.pe|
|000002f0| 72 20 73 61 6d 70 6c 65 | 2c 20 65 74 63 2e 0d 5c |r sample|, etc..\|
|00000300| 65 6e 64 7b 65 78 63 64 | 65 73 63 7d 0d 0d 5c 62 |end{excd|esc}..\b|
|00000310| 65 67 69 6e 7b 66 75 6e | 63 64 65 73 63 7d 7b 61 |egin{fun|cdesc}{a|
|00000320| 64 64 7d 7b 66 72 61 67 | 6d 65 6e 74 31 5c 2c 20 |dd}{frag|ment1\, |
|00000330| 66 72 61 67 6d 65 6e 74 | 32 5c 2c 20 77 69 64 74 |fragment|2\, widt|
|00000340| 68 7d 0d 54 68 69 73 20 | 66 75 6e 63 74 69 6f 6e |h}.This |function|
|00000350| 20 72 65 74 75 72 6e 73 | 20 61 20 66 72 61 67 6d | returns| a fragm|
|00000360| 65 6e 74 20 74 68 61 74 | 20 69 73 20 74 68 65 20 |ent that| is the |
|00000370| 61 64 64 69 74 69 6f 6e | 20 6f 66 20 74 68 65 20 |addition| of the |
|00000380| 74 77 6f 20 73 61 6d 70 | 6c 65 73 0d 70 61 73 73 |two samp|les.pass|
|00000390| 65 64 20 61 73 20 70 61 | 72 61 6d 65 74 65 72 73 |ed as pa|rameters|
|000003a0| 2e 20 5c 76 61 72 7b 77 | 69 64 74 68 7d 20 69 73 |. \var{w|idth} is|
|000003b0| 20 74 68 65 20 73 61 6d | 70 6c 65 20 77 69 64 74 | the sam|ple widt|
|000003c0| 68 20 69 6e 20 62 79 74 | 65 73 2c 20 65 69 74 68 |h in byt|es, eith|
|000003d0| 65 72 0d 5c 63 6f 64 65 | 7b 31 7d 2c 20 5c 63 6f |er.\code|{1}, \co|
|000003e0| 64 65 7b 32 7d 20 6f 72 | 20 5c 63 6f 64 65 7b 34 |de{2} or| \code{4|
|000003f0| 7d 2e 20 42 6f 74 68 20 | 66 72 61 67 6d 65 6e 74 |}. Both |fragment|
|00000400| 73 20 73 68 6f 75 6c 64 | 20 68 61 76 65 20 74 68 |s should| have th|
|00000410| 65 20 73 61 6d 65 20 6c | 65 6e 67 74 68 2e 0d 5c |e same l|ength..\|
|00000420| 65 6e 64 7b 66 75 6e 63 | 64 65 73 63 7d 0d 0d 5c |end{func|desc}..\|
|00000430| 62 65 67 69 6e 7b 66 75 | 6e 63 64 65 73 63 7d 7b |begin{fu|ncdesc}{|
|00000440| 61 64 70 63 6d 32 6c 69 | 6e 7d 7b 61 64 70 63 6d |adpcm2li|n}{adpcm|
|00000450| 66 72 61 67 6d 65 6e 74 | 5c 2c 20 77 69 64 74 68 |fragment|\, width|
|00000460| 5c 2c 20 73 74 61 74 65 | 7d 0d 54 68 69 73 20 72 |\, state|}.This r|
|00000470| 6f 75 74 69 6e 65 20 64 | 65 63 6f 64 65 73 20 61 |outine d|ecodes a|
|00000480| 6e 20 49 6e 74 65 6c 2f | 44 56 49 20 41 44 50 43 |n Intel/|DVI ADPC|
|00000490| 4d 20 63 6f 64 65 64 20 | 66 72 61 67 6d 65 6e 74 |M coded |fragment|
|000004a0| 20 74 6f 20 61 20 6c 69 | 6e 65 61 72 0d 66 72 61 | to a li|near.fra|
|000004b0| 67 6d 65 6e 74 2e 20 53 | 65 65 20 74 68 65 20 64 |gment. S|ee the d|
|000004c0| 65 73 63 72 69 70 74 69 | 6f 6e 20 6f 66 20 5c 63 |escripti|on of \c|
|000004d0| 6f 64 65 7b 6c 69 6e 32 | 61 64 70 63 6d 7d 20 66 |ode{lin2|adpcm} f|
|000004e0| 6f 72 20 64 65 74 61 69 | 6c 73 20 6f 6e 20 41 44 |or detai|ls on AD|
|000004f0| 50 43 4d 0d 63 6f 64 69 | 6e 67 2e 20 54 68 65 20 |PCM.codi|ng. The |
|00000500| 72 6f 75 74 69 6e 65 20 | 72 65 74 75 72 6e 73 20 |routine |returns |
|00000510| 61 20 74 75 70 6c 65 0d | 5c 63 6f 64 65 7b 28 5c |a tuple.|\code{(\|
|00000520| 76 61 72 7b 73 61 6d 70 | 6c 65 7d 2c 20 5c 76 61 |var{samp|le}, \va|
|00000530| 72 7b 6e 65 77 73 74 61 | 74 65 7d 29 7d 0d 77 68 |r{newsta|te})}.wh|
|00000540| 65 72 65 20 74 68 65 20 | 73 61 6d 70 6c 65 20 68 |ere the |sample h|
|00000550| 61 73 20 74 68 65 20 77 | 69 64 74 68 20 73 70 65 |as the w|idth spe|
|00000560| 63 69 66 69 65 64 20 69 | 6e 20 5c 76 61 72 7b 77 |cified i|n \var{w|
|00000570| 69 64 74 68 7d 2e 0d 5c | 65 6e 64 7b 66 75 6e 63 |idth}..\|end{func|
|00000580| 64 65 73 63 7d 0d 0d 5c | 62 65 67 69 6e 7b 66 75 |desc}..\|begin{fu|
|00000590| 6e 63 64 65 73 63 7d 7b | 61 64 70 63 6d 33 32 6c |ncdesc}{|adpcm32l|
|000005a0| 69 6e 7d 7b 61 64 70 63 | 6d 66 72 61 67 6d 65 6e |in}{adpc|mfragmen|
|000005b0| 74 5c 2c 20 77 69 64 74 | 68 5c 2c 20 73 74 61 74 |t\, widt|h\, stat|
|000005c0| 65 7d 0d 54 68 69 73 20 | 72 6f 75 74 69 6e 65 20 |e}.This |routine |
|000005d0| 64 65 63 6f 64 65 73 20 | 61 6e 20 61 6c 74 65 72 |decodes |an alter|
|000005e0| 6e 61 74 69 76 65 20 33 | 2d 62 69 74 20 41 44 50 |native 3|-bit ADP|
|000005f0| 43 4d 20 63 6f 64 65 2e | 20 53 65 65 0d 5c 63 6f |CM code.| See.\co|
|00000600| 64 65 7b 6c 69 6e 32 61 | 64 70 63 6d 33 7d 20 66 |de{lin2a|dpcm3} f|
|00000610| 6f 72 20 64 65 74 61 69 | 6c 73 2e 0d 5c 65 6e 64 |or detai|ls..\end|
|00000620| 7b 66 75 6e 63 64 65 73 | 63 7d 0d 0d 5c 62 65 67 |{funcdes|c}..\beg|
|00000630| 69 6e 7b 66 75 6e 63 64 | 65 73 63 7d 7b 61 76 67 |in{funcd|esc}{avg|
|00000640| 7d 7b 66 72 61 67 6d 65 | 6e 74 5c 2c 20 77 69 64 |}{fragme|nt\, wid|
|00000650| 74 68 7d 0d 54 68 69 73 | 20 66 75 6e 63 74 69 6f |th}.This| functio|
|00000660| 6e 20 72 65 74 75 72 6e | 73 20 74 68 65 20 61 76 |n return|s the av|
|00000670| 65 72 61 67 65 20 6f 76 | 65 72 20 61 6c 6c 20 73 |erage ov|er all s|
|00000680| 61 6d 70 6c 65 73 20 69 | 6e 20 74 68 65 20 66 72 |amples i|n the fr|
|00000690| 61 67 6d 65 6e 74 2e 0d | 5c 65 6e 64 7b 66 75 6e |agment..|\end{fun|
|000006a0| 63 64 65 73 63 7d 0d 0d | 5c 62 65 67 69 6e 7b 66 |cdesc}..|\begin{f|
|000006b0| 75 6e 63 64 65 73 63 7d | 7b 61 76 67 70 70 7d 7b |uncdesc}|{avgpp}{|
|000006c0| 66 72 61 67 6d 65 6e 74 | 5c 2c 20 77 69 64 74 68 |fragment|\, width|
|000006d0| 7d 0d 54 68 69 73 20 66 | 75 6e 63 74 69 6f 6e 20 |}.This f|unction |
|000006e0| 72 65 74 75 72 6e 73 20 | 74 68 65 20 61 76 65 72 |returns |the aver|
|000006f0| 61 67 65 20 70 65 61 6b | 2d 70 65 61 6b 20 76 61 |age peak|-peak va|
|00000700| 6c 75 65 20 6f 76 65 72 | 20 61 6c 6c 20 73 61 6d |lue over| all sam|
|00000710| 70 6c 65 73 20 69 6e 0d | 74 68 65 20 66 72 61 67 |ples in.|the frag|
|00000720| 6d 65 6e 74 2e 20 4e 6f | 20 66 69 6c 74 65 72 69 |ment. No| filteri|
|00000730| 6e 67 20 69 73 20 64 6f | 6e 65 2c 20 73 6f 20 74 |ng is do|ne, so t|
|00000740| 68 65 20 75 73 65 66 75 | 6c 6e 65 73 73 20 6f 66 |he usefu|lness of|
|00000750| 20 74 68 69 73 20 72 6f | 75 74 69 6e 65 0d 69 73 | this ro|utine.is|
|00000760| 20 71 75 65 73 74 69 6f | 6e 61 62 6c 65 2e 0d 5c | questio|nable..\|
|00000770| 65 6e 64 7b 66 75 6e 63 | 64 65 73 63 7d 0d 0d 5c |end{func|desc}..\|
|00000780| 62 65 67 69 6e 7b 66 75 | 6e 63 64 65 73 63 7d 7b |begin{fu|ncdesc}{|
|00000790| 62 69 61 73 7d 7b 66 72 | 61 67 6d 65 6e 74 5c 2c |bias}{fr|agment\,|
|000007a0| 20 77 69 64 74 68 5c 2c | 20 62 69 61 73 7d 0d 54 | width\,| bias}.T|
|000007b0| 68 69 73 20 66 75 6e 63 | 74 69 6f 6e 20 72 65 74 |his func|tion ret|
|000007c0| 75 72 6e 73 20 61 20 66 | 72 61 67 6d 65 6e 74 20 |urns a f|ragment |
|000007d0| 74 68 61 74 20 69 73 20 | 74 68 65 20 6f 72 69 67 |that is |the orig|
|000007e0| 69 6e 61 6c 20 66 72 61 | 67 6d 65 6e 74 20 77 69 |inal fra|gment wi|
|000007f0| 74 68 20 61 0d 62 69 61 | 73 20 61 64 64 65 64 20 |th a.bia|s added |
|00000800| 74 6f 20 65 61 63 68 20 | 73 61 6d 70 6c 65 2e 0d |to each |sample..|
|00000810| 5c 65 6e 64 7b 66 75 6e | 63 64 65 73 63 7d 0d 0d |\end{fun|cdesc}..|
|00000820| 5c 62 65 67 69 6e 7b 66 | 75 6e 63 64 65 73 63 7d |\begin{f|uncdesc}|
|00000830| 7b 63 72 6f 73 73 7d 7b | 66 72 61 67 6d 65 6e 74 |{cross}{|fragment|
|00000840| 5c 2c 20 77 69 64 74 68 | 7d 0d 54 68 69 73 20 66 |\, width|}.This f|
|00000850| 75 6e 63 74 69 6f 6e 20 | 72 65 74 75 72 6e 73 20 |unction |returns |
|00000860| 74 68 65 20 6e 75 6d 62 | 65 72 20 6f 66 20 7a 65 |the numb|er of ze|
|00000870| 72 6f 20 63 72 6f 73 73 | 69 6e 67 73 20 69 6e 20 |ro cross|ings in |
|00000880| 74 68 65 20 66 72 61 67 | 6d 65 6e 74 0d 70 61 73 |the frag|ment.pas|
|00000890| 73 65 64 20 61 73 20 61 | 6e 20 61 72 67 75 6d 65 |sed as a|n argume|
|000008a0| 6e 74 2e 0d 5c 65 6e 64 | 7b 66 75 6e 63 64 65 73 |nt..\end|{funcdes|
|000008b0| 63 7d 0d 0d 5c 62 65 67 | 69 6e 7b 66 75 6e 63 64 |c}..\beg|in{funcd|
|000008c0| 65 73 63 7d 7b 66 69 6e | 64 66 61 63 74 6f 72 7d |esc}{fin|dfactor}|
|000008d0| 7b 66 72 61 67 6d 65 6e | 74 5c 2c 20 72 65 66 65 |{fragmen|t\, refe|
|000008e0| 72 65 6e 63 65 7d 0d 54 | 68 69 73 20 72 6f 75 74 |rence}.T|his rout|
|000008f0| 69 6e 65 20 28 77 68 69 | 63 68 20 6f 6e 6c 79 20 |ine (whi|ch only |
|00000900| 61 63 63 65 70 74 73 20 | 32 2d 62 79 74 65 20 73 |accepts |2-byte s|
|00000910| 61 6d 70 6c 65 20 66 72 | 61 67 6d 65 6e 74 73 29 |ample fr|agments)|
|00000920| 20 63 61 6c 63 75 6c 61 | 74 65 73 20 61 0d 66 61 | calcula|tes a.fa|
|00000930| 63 74 6f 72 20 5c 76 61 | 72 7b 46 7d 20 73 75 63 |ctor \va|r{F} suc|
|00000940| 68 20 74 68 61 74 20 5c | 63 6f 64 65 7b 72 6d 73 |h that \|code{rms|
|00000950| 28 61 64 64 28 66 72 61 | 67 6d 65 6e 74 2c 20 6d |(add(fra|gment, m|
|00000960| 75 6c 28 72 65 66 65 72 | 65 6e 63 65 2c 20 2d 46 |ul(refer|ence, -F|
|00000970| 29 29 29 7d 0d 69 73 20 | 6d 69 6e 69 6d 61 6c 2c |)))}.is |minimal,|
|00000980| 20 69 2e 65 2e 20 69 74 | 20 63 61 6c 63 75 6c 61 | i.e. it| calcula|
|00000990| 74 65 73 20 74 68 65 20 | 66 61 63 74 6f 72 20 77 |tes the |factor w|
|000009a0| 69 74 68 20 77 68 69 63 | 68 20 79 6f 75 20 73 68 |ith whic|h you sh|
|000009b0| 6f 75 6c 64 0d 6d 75 6c | 74 69 70 6c 79 20 5c 76 |ould.mul|tiply \v|
|000009c0| 61 72 7b 72 65 66 65 72 | 65 6e 63 65 7d 20 74 6f |ar{refer|ence} to|
|000009d0| 20 6d 61 6b 65 20 69 74 | 20 6d 61 74 63 68 20 61 | make it| match a|
|000009e0| 73 20 67 6f 6f 64 20 61 | 73 20 70 6f 73 73 69 62 |s good a|s possib|
|000009f0| 6c 65 20 74 6f 0d 5c 76 | 61 72 7b 66 72 61 67 6d |le to.\v|ar{fragm|
|00000a00| 65 6e 74 7d 2e 20 54 68 | 65 20 66 72 61 67 6d 65 |ent}. Th|e fragme|
|00000a10| 6e 74 73 20 73 68 6f 75 | 6c 64 20 62 65 20 74 68 |nts shou|ld be th|
|00000a20| 65 20 73 61 6d 65 20 73 | 69 7a 65 2e 0d 0d 54 68 |e same s|ize...Th|
|00000a30| 65 20 74 69 6d 65 20 74 | 61 6b 65 6e 20 62 79 20 |e time t|aken by |
|00000a40| 74 68 69 73 20 72 6f 75 | 74 69 6e 65 20 69 73 20 |this rou|tine is |
|00000a50| 70 72 6f 70 6f 72 74 69 | 6f 6e 61 6c 20 74 6f 20 |proporti|onal to |
|00000a60| 5c 63 6f 64 65 7b 6c 65 | 6e 28 66 72 61 67 6d 65 |\code{le|n(fragme|
|00000a70| 6e 74 29 7d 2e 20 0d 5c | 65 6e 64 7b 66 75 6e 63 |nt)}. .\|end{func|
|00000a80| 64 65 73 63 7d 0d 0d 5c | 62 65 67 69 6e 7b 66 75 |desc}..\|begin{fu|
|00000a90| 6e 63 64 65 73 63 7d 7b | 66 69 6e 64 66 69 74 7d |ncdesc}{|findfit}|
|00000aa0| 7b 66 72 61 67 6d 65 6e | 74 5c 2c 20 72 65 66 65 |{fragmen|t\, refe|
|00000ab0| 72 65 6e 63 65 7d 0d 54 | 68 69 73 20 72 6f 75 74 |rence}.T|his rout|
|00000ac0| 69 6e 65 20 28 77 68 69 | 63 68 20 6f 6e 6c 79 20 |ine (whi|ch only |
|00000ad0| 61 63 63 65 70 74 73 20 | 32 2d 62 79 74 65 20 73 |accepts |2-byte s|
|00000ae0| 61 6d 70 6c 65 20 66 72 | 61 67 6d 65 6e 74 73 29 |ample fr|agments)|
|00000af0| 20 74 72 69 65 73 20 74 | 6f 0d 6d 61 74 63 68 20 | tries t|o.match |
|00000b00| 5c 76 61 72 7b 72 65 66 | 65 72 65 6e 63 65 7d 20 |\var{ref|erence} |
|00000b10| 61 73 20 67 6f 6f 64 20 | 61 73 20 70 6f 73 73 69 |as good |as possi|
|00000b20| 62 6c 65 20 74 6f 20 61 | 20 70 6f 72 74 69 6f 6e |ble to a| portion|
|00000b30| 20 6f 66 0d 5c 76 61 72 | 7b 66 72 61 67 6d 65 6e | of.\var|{fragmen|
|00000b40| 74 7d 20 28 77 68 69 63 | 68 20 73 68 6f 75 6c 64 |t} (whic|h should|
|00000b50| 20 62 65 20 74 68 65 20 | 6c 6f 6e 67 65 72 20 66 | be the |longer f|
|00000b60| 72 61 67 6d 65 6e 74 29 | 2e 20 49 74 0d 28 63 6f |ragment)|. It.(co|
|00000b70| 6e 63 65 70 74 75 61 6c | 6c 79 29 20 64 6f 65 73 |nceptual|ly) does|
|00000b80| 20 74 68 69 73 20 62 79 | 20 74 61 6b 69 6e 67 20 | this by| taking |
|00000b90| 73 6c 69 63 65 73 20 6f | 75 74 20 6f 66 20 5c 76 |slices o|ut of \v|
|00000ba0| 61 72 7b 66 72 61 67 6d | 65 6e 74 7d 2c 20 75 73 |ar{fragm|ent}, us|
|00000bb0| 69 6e 67 0d 5c 63 6f 64 | 65 7b 66 69 6e 64 66 61 |ing.\cod|e{findfa|
|00000bc0| 63 74 6f 72 7d 20 74 6f | 20 63 6f 6d 70 75 74 65 |ctor} to| compute|
|00000bd0| 20 74 68 65 20 62 65 73 | 74 20 6d 61 74 63 68 2c | the bes|t match,|
|00000be0| 20 61 6e 64 20 6d 69 6e | 69 6d 69 7a 69 6e 67 20 | and min|imizing |
|00000bf0| 74 68 65 0d 72 65 73 75 | 6c 74 2e 0d 49 74 20 72 |the.resu|lt..It r|
|00000c00| 65 74 75 72 6e 73 20 61 | 20 74 75 70 6c 65 20 5c |eturns a| tuple \|
|00000c10| 63 6f 64 65 7b 28 5c 76 | 61 72 7b 6f 66 66 73 65 |code{(\v|ar{offse|
|00000c20| 74 7d 2c 20 5c 76 61 72 | 7b 66 61 63 74 6f 72 7d |t}, \var|{factor}|
|00000c30| 29 7d 20 77 69 74 68 20 | 5c 76 61 72 7b 6f 66 66 |)} with |\var{off|
|00000c40| 73 65 74 7d 20 74 68 65 | 0d 28 69 6e 74 65 67 65 |set} the|.(intege|
|00000c50| 72 29 20 6f 66 66 73 65 | 74 20 69 6e 74 6f 20 5c |r) offse|t into \|
|00000c60| 76 61 72 7b 66 72 61 67 | 6d 65 6e 74 7d 20 77 68 |var{frag|ment} wh|
|00000c70| 65 72 65 20 74 68 65 20 | 6f 70 74 69 6d 61 6c 20 |ere the |optimal |
|00000c80| 6d 61 74 63 68 20 73 74 | 61 72 74 65 64 0d 61 6e |match st|arted.an|
|00000c90| 64 20 5c 76 61 72 7b 66 | 61 63 74 6f 72 7d 20 74 |d \var{f|actor} t|
|00000ca0| 68 65 20 66 6c 6f 61 74 | 69 6e 67 2d 70 6f 69 6e |he float|ing-poin|
|00000cb0| 74 20 66 61 63 74 6f 72 | 20 61 73 20 70 65 72 20 |t factor| as per |
|00000cc0| 5c 63 6f 64 65 7b 66 69 | 6e 64 66 61 63 74 6f 72 |\code{fi|ndfactor|
|00000cd0| 7d 2e 0d 5c 65 6e 64 7b | 66 75 6e 63 64 65 73 63 |}..\end{|funcdesc|
|00000ce0| 7d 0d 0d 5c 62 65 67 69 | 6e 7b 66 75 6e 63 64 65 |}..\begi|n{funcde|
|00000cf0| 73 63 7d 7b 66 69 6e 64 | 6d 61 78 7d 7b 66 72 61 |sc}{find|max}{fra|
|00000d00| 67 6d 65 6e 74 5c 2c 20 | 6c 65 6e 67 74 68 7d 0d |gment\, |length}.|
|00000d10| 54 68 69 73 20 72 6f 75 | 74 69 6e 65 20 28 77 68 |This rou|tine (wh|
|00000d20| 69 63 68 20 6f 6e 6c 79 | 20 61 63 63 65 70 74 73 |ich only| accepts|
|00000d30| 20 32 2d 62 79 74 65 20 | 73 61 6d 70 6c 65 20 66 | 2-byte |sample f|
|00000d40| 72 61 67 6d 65 6e 74 73 | 29 20 73 65 61 72 63 68 |ragments|) search|
|00000d50| 65 73 0d 5c 76 61 72 7b | 66 72 61 67 6d 65 6e 74 |es.\var{|fragment|
|00000d60| 7d 20 66 6f 72 20 61 20 | 73 6c 69 63 65 20 6f 66 |} for a |slice of|
|00000d70| 20 6c 65 6e 67 74 68 20 | 5c 76 61 72 7b 6c 65 6e | length |\var{len|
|00000d80| 67 74 68 7d 20 73 61 6d | 70 6c 65 73 20 28 6e 6f |gth} sam|ples (no|
|00000d90| 74 20 62 79 74 65 73 21 | 29 0d 77 69 74 68 20 6d |t bytes!|).with m|
|00000da0| 61 78 69 6d 75 6d 20 65 | 6e 65 72 67 79 2c 20 69 |aximum e|nergy, i|
|00000db0| 2e 65 2e 20 69 74 20 72 | 65 74 75 72 6e 73 20 5c |.e. it r|eturns \|
|00000dc0| 76 61 72 7b 69 7d 20 66 | 6f 72 20 77 68 69 63 68 |var{i} f|or which|
|00000dd0| 0d 5c 63 6f 64 65 7b 72 | 6d 73 28 66 72 61 67 6d |.\code{r|ms(fragm|
|00000de0| 65 6e 74 5b 69 2a 32 3a | 28 69 2b 6c 65 6e 67 74 |ent[i*2:|(i+lengt|
|00000df0| 68 29 2a 32 5d 29 7d 20 | 69 73 20 6d 61 78 69 6d |h)*2])} |is maxim|
|00000e00| 61 6c 2e 0d 0d 54 68 65 | 20 72 6f 75 74 69 6e 65 |al...The| routine|
|00000e10| 20 74 61 6b 65 73 20 74 | 69 6d 65 20 70 72 6f 70 | takes t|ime prop|
|00000e20| 6f 72 74 69 6f 6e 61 6c | 20 74 6f 20 5c 63 6f 64 |ortional| to \cod|
|00000e30| 65 7b 6c 65 6e 28 66 72 | 61 67 6d 65 6e 74 29 7d |e{len(fr|agment)}|
|00000e40| 2e 0d 5c 65 6e 64 7b 66 | 75 6e 63 64 65 73 63 7d |..\end{f|uncdesc}|
|00000e50| 0d 0d 5c 62 65 67 69 6e | 7b 66 75 6e 63 64 65 73 |..\begin|{funcdes|
|00000e60| 63 7d 7b 67 65 74 73 61 | 6d 70 6c 65 7d 7b 66 72 |c}{getsa|mple}{fr|
|00000e70| 61 67 6d 65 6e 74 5c 2c | 20 77 69 64 74 68 5c 2c |agment\,| width\,|
|00000e80| 20 69 6e 64 65 78 7d 0d | 54 68 69 73 20 66 75 6e | index}.|This fun|
|00000e90| 63 74 69 6f 6e 20 72 65 | 74 75 72 6e 73 20 74 68 |ction re|turns th|
|00000ea0| 65 20 76 61 6c 75 65 20 | 6f 66 20 73 61 6d 70 6c |e value |of sampl|
|00000eb0| 65 20 5c 76 61 72 7b 69 | 6e 64 65 78 7d 20 66 72 |e \var{i|ndex} fr|
|00000ec0| 6f 6d 20 74 68 65 0d 66 | 72 61 67 6d 65 6e 74 2e |om the.f|ragment.|
|00000ed0| 0d 5c 65 6e 64 7b 66 75 | 6e 63 64 65 73 63 7d 0d |.\end{fu|ncdesc}.|
|00000ee0| 0d 5c 62 65 67 69 6e 7b | 66 75 6e 63 64 65 73 63 |.\begin{|funcdesc|
|00000ef0| 7d 7b 6c 69 6e 32 6c 69 | 6e 7d 7b 66 72 61 67 6d |}{lin2li|n}{fragm|
|00000f00| 65 6e 74 5c 2c 20 77 69 | 64 74 68 5c 2c 20 6e 65 |ent\, wi|dth\, ne|
|00000f10| 77 77 69 64 74 68 7d 0d | 54 68 69 73 20 66 75 6e |wwidth}.|This fun|
|00000f20| 63 74 69 6f 6e 20 63 6f | 6e 76 65 72 74 73 20 73 |ction co|nverts s|
|00000f30| 61 6d 70 6c 65 73 20 62 | 65 74 77 65 65 6e 20 31 |amples b|etween 1|
|00000f40| 2d 2c 20 32 2d 20 61 6e | 64 20 34 2d 62 79 74 65 |-, 2- an|d 4-byte|
|00000f50| 20 66 6f 72 6d 61 74 73 | 2e 0d 5c 65 6e 64 7b 66 | formats|..\end{f|
|00000f60| 75 6e 63 64 65 73 63 7d | 0d 0d 5c 62 65 67 69 6e |uncdesc}|..\begin|
|00000f70| 7b 66 75 6e 63 64 65 73 | 63 7d 7b 6c 69 6e 32 61 |{funcdes|c}{lin2a|
|00000f80| 64 70 63 6d 7d 7b 66 72 | 61 67 6d 65 6e 74 5c 2c |dpcm}{fr|agment\,|
|00000f90| 20 77 69 64 74 68 5c 2c | 20 73 74 61 74 65 7d 0d | width\,| state}.|
|00000fa0| 54 68 69 73 20 66 75 6e | 63 74 69 6f 6e 20 63 6f |This fun|ction co|
|00000fb0| 6e 76 65 72 74 73 20 73 | 61 6d 70 6c 65 73 20 74 |nverts s|amples t|
|00000fc0| 6f 20 34 20 62 69 74 20 | 49 6e 74 65 6c 2f 44 56 |o 4 bit |Intel/DV|
|00000fd0| 49 20 41 44 50 43 4d 20 | 65 6e 63 6f 64 69 6e 67 |I ADPCM |encoding|
|00000fe0| 2e 0d 41 44 50 43 4d 20 | 63 6f 64 69 6e 67 20 69 |..ADPCM |coding i|
|00000ff0| 73 20 61 6e 20 61 64 61 | 70 74 69 76 65 20 63 6f |s an ada|ptive co|
|00001000| 64 69 6e 67 20 73 63 68 | 65 6d 65 2c 20 77 68 65 |ding sch|eme, whe|
|00001010| 72 65 62 79 20 65 61 63 | 68 20 34 20 62 69 74 20 |reby eac|h 4 bit |
|00001020| 6e 75 6d 62 65 72 0d 69 | 73 20 74 68 65 20 64 69 |number.i|s the di|
|00001030| 66 66 65 72 65 6e 63 65 | 20 62 65 74 77 65 65 6e |fference| between|
|00001040| 20 6f 6e 65 20 73 61 6d | 70 6c 65 20 61 6e 64 20 | one sam|ple and |
|00001050| 74 68 65 20 6e 65 78 74 | 2c 20 64 69 76 69 64 65 |the next|, divide|
|00001060| 64 20 62 79 20 61 0d 28 | 76 61 72 79 69 6e 67 29 |d by a.(|varying)|
|00001070| 20 73 74 65 70 2e 20 54 | 68 65 20 49 6e 74 65 6c | step. T|he Intel|
|00001080| 2f 44 56 49 20 41 44 50 | 43 4d 20 61 6c 67 6f 72 |/DVI ADP|CM algor|
|00001090| 69 74 68 6d 20 68 61 73 | 20 62 65 65 6e 20 73 65 |ithm has| been se|
|000010a0| 6c 65 63 74 65 64 20 66 | 6f 72 0d 75 73 65 20 62 |lected f|or.use b|
|000010b0| 79 20 74 68 65 20 49 4d | 41 2c 20 73 6f 20 69 74 |y the IM|A, so it|
|000010c0| 20 6d 61 79 20 77 65 6c | 6c 20 62 65 63 6f 6d 65 | may wel|l become|
|000010d0| 20 61 20 73 74 61 6e 64 | 61 72 64 2e 0d 0d 5c 63 | a stand|ard...\c|
|000010e0| 6f 64 65 7b 53 74 61 74 | 65 7d 20 69 73 20 61 20 |ode{Stat|e} is a |
|000010f0| 74 75 70 6c 65 20 63 6f | 6e 74 61 69 6e 69 6e 67 |tuple co|ntaining|
|00001100| 20 74 68 65 20 73 74 61 | 74 65 20 6f 66 20 74 68 | the sta|te of th|
|00001110| 65 20 63 6f 64 65 72 2e | 20 54 68 65 20 63 6f 64 |e coder.| The cod|
|00001120| 65 72 0d 72 65 74 75 72 | 6e 73 20 61 20 74 75 70 |er.retur|ns a tup|
|00001130| 6c 65 20 5c 63 6f 64 65 | 7b 28 5c 76 61 72 7b 61 |le \code|{(\var{a|
|00001140| 64 70 63 6d 66 72 61 67 | 7d 2c 20 5c 76 61 72 7b |dpcmfrag|}, \var{|
|00001150| 6e 65 77 73 74 61 74 65 | 7d 29 7d 2c 20 61 6e 64 |newstate|})}, and|
|00001160| 20 74 68 65 0d 5c 76 61 | 72 7b 6e 65 77 73 74 61 | the.\va|r{newsta|
|00001170| 74 65 7d 20 73 68 6f 75 | 6c 64 20 62 65 20 70 61 |te} shou|ld be pa|
|00001180| 73 73 65 64 20 74 6f 20 | 74 68 65 20 6e 65 78 74 |ssed to |the next|
|00001190| 20 63 61 6c 6c 20 6f 66 | 20 6c 69 6e 32 61 64 70 | call of| lin2adp|
|000011a0| 63 6d 2e 20 20 49 6e 20 | 74 68 65 0d 69 6e 69 74 |cm. In |the.init|
|000011b0| 69 61 6c 20 63 61 6c 6c | 20 5c 63 6f 64 65 7b 4e |ial call| \code{N|
|000011c0| 6f 6e 65 7d 20 63 61 6e | 20 62 65 20 70 61 73 73 |one} can| be pass|
|000011d0| 65 64 20 61 73 20 74 68 | 65 20 73 74 61 74 65 2e |ed as th|e state.|
|000011e0| 20 5c 76 61 72 7b 61 64 | 70 63 6d 66 72 61 67 7d | \var{ad|pcmfrag}|
|000011f0| 20 69 73 0d 74 68 65 20 | 41 44 50 43 4d 20 63 6f | is.the |ADPCM co|
|00001200| 64 65 64 20 66 72 61 67 | 6d 65 6e 74 20 70 61 63 |ded frag|ment pac|
|00001210| 6b 65 64 20 32 20 34 2d | 62 69 74 20 76 61 6c 75 |ked 2 4-|bit valu|
|00001220| 65 73 20 70 65 72 20 62 | 79 74 65 2e 0d 5c 65 6e |es per b|yte..\en|
|00001230| 64 7b 66 75 6e 63 64 65 | 73 63 7d 0d 0d 5c 62 65 |d{funcde|sc}..\be|
|00001240| 67 69 6e 7b 66 75 6e 63 | 64 65 73 63 7d 7b 6c 69 |gin{func|desc}{li|
|00001250| 6e 32 61 64 70 63 6d 33 | 7d 7b 66 72 61 67 6d 65 |n2adpcm3|}{fragme|
|00001260| 6e 74 5c 2c 20 77 69 64 | 74 68 5c 2c 20 73 74 61 |nt\, wid|th\, sta|
|00001270| 74 65 7d 0d 54 68 69 73 | 20 69 73 20 61 6e 20 61 |te}.This| is an a|
|00001280| 6c 74 65 72 6e 61 74 69 | 76 65 20 41 44 50 43 4d |lternati|ve ADPCM|
|00001290| 20 63 6f 64 65 72 20 74 | 68 61 74 20 75 73 65 73 | coder t|hat uses|
|000012a0| 20 6f 6e 6c 79 20 33 20 | 62 69 74 73 20 70 65 72 | only 3 |bits per|
|000012b0| 20 73 61 6d 70 6c 65 2e | 0d 49 74 20 69 73 20 6e | sample.|.It is n|
|000012c0| 6f 74 20 63 6f 6d 70 61 | 74 69 62 6c 65 20 77 69 |ot compa|tible wi|
|000012d0| 74 68 20 74 68 65 20 49 | 6e 74 65 6c 2f 44 56 49 |th the I|ntel/DVI|
|000012e0| 20 41 44 50 43 4d 20 63 | 6f 64 65 72 20 61 6e 64 | ADPCM c|oder and|
|000012f0| 20 69 74 73 20 6f 75 74 | 70 75 74 20 69 73 0d 6e | its out|put is.n|
|00001300| 6f 74 20 70 61 63 6b 65 | 64 20 28 64 75 65 20 74 |ot packe|d (due t|
|00001310| 6f 20 6c 61 7a 69 6e 65 | 73 73 20 6f 6e 20 74 68 |o lazine|ss on th|
|00001320| 65 20 73 69 64 65 20 6f | 66 20 74 68 65 20 61 75 |e side o|f the au|
|00001330| 74 68 6f 72 29 2e 20 49 | 74 73 20 75 73 65 20 69 |thor). I|ts use i|
|00001340| 73 0d 64 69 73 63 6f 75 | 72 61 67 65 64 2e 0d 5c |s.discou|raged..\|
|00001350| 65 6e 64 7b 66 75 6e 63 | 64 65 73 63 7d 0d 0d 5c |end{func|desc}..\|
|00001360| 62 65 67 69 6e 7b 66 75 | 6e 63 64 65 73 63 7d 7b |begin{fu|ncdesc}{|
|00001370| 6c 69 6e 32 75 6c 61 77 | 7d 7b 66 72 61 67 6d 65 |lin2ulaw|}{fragme|
|00001380| 6e 74 5c 2c 20 77 69 64 | 74 68 7d 0d 54 68 69 73 |nt\, wid|th}.This|
|00001390| 20 66 75 6e 63 74 69 6f | 6e 20 63 6f 6e 76 65 72 | functio|n conver|
|000013a0| 74 73 20 73 61 6d 70 6c | 65 73 20 69 6e 20 74 68 |ts sampl|es in th|
|000013b0| 65 20 61 75 64 69 6f 20 | 66 72 61 67 6d 65 6e 74 |e audio |fragment|
|000013c0| 20 74 6f 20 55 2d 4c 41 | 57 20 65 6e 63 6f 64 69 | to U-LA|W encodi|
|000013d0| 6e 67 0d 61 6e 64 20 72 | 65 74 75 72 6e 73 20 74 |ng.and r|eturns t|
|000013e0| 68 69 73 20 61 73 20 61 | 20 50 79 74 68 6f 6e 20 |his as a| Python |
|000013f0| 73 74 72 69 6e 67 2e 20 | 55 2d 4c 41 57 20 69 73 |string. |U-LAW is|
|00001400| 20 61 6e 20 61 75 64 69 | 6f 20 65 6e 63 6f 64 69 | an audi|o encodi|
|00001410| 6e 67 20 66 6f 72 6d 61 | 74 0d 77 68 65 72 65 62 |ng forma|t.whereb|
|00001420| 79 20 79 6f 75 20 67 65 | 74 20 61 20 64 79 6e 61 |y you ge|t a dyna|
|00001430| 6d 69 63 20 72 61 6e 67 | 65 20 6f 66 20 61 62 6f |mic rang|e of abo|
|00001440| 75 74 20 31 34 20 62 69 | 74 73 20 75 73 69 6e 67 |ut 14 bi|ts using|
|00001450| 20 6f 6e 6c 79 20 38 20 | 62 69 74 0d 73 61 6d 70 | only 8 |bit.samp|
|00001460| 6c 65 73 2e 20 49 74 20 | 69 73 20 75 73 65 64 20 |les. It |is used |
|00001470| 62 79 20 74 68 65 20 53 | 75 6e 20 61 75 64 69 6f |by the S|un audio|
|00001480| 20 68 61 72 64 77 61 72 | 65 2c 20 61 6d 6f 6e 67 | hardwar|e, among|
|00001490| 20 6f 74 68 65 72 73 2e | 0d 5c 65 6e 64 7b 66 75 | others.|.\end{fu|
|000014a0| 6e 63 64 65 73 63 7d 0d | 0d 5c 62 65 67 69 6e 7b |ncdesc}.|.\begin{|
|000014b0| 66 75 6e 63 64 65 73 63 | 7d 7b 6d 69 6e 6d 61 78 |funcdesc|}{minmax|
|000014c0| 7d 7b 66 72 61 67 6d 65 | 6e 74 5c 2c 20 77 69 64 |}{fragme|nt\, wid|
|000014d0| 74 68 7d 0d 54 68 69 73 | 20 66 75 6e 63 74 69 6f |th}.This| functio|
|000014e0| 6e 20 72 65 74 75 72 6e | 73 20 61 20 74 75 70 6c |n return|s a tupl|
|000014f0| 65 20 63 6f 6e 73 69 73 | 74 69 6e 67 20 6f 66 20 |e consis|ting of |
|00001500| 74 68 65 20 6d 69 6e 69 | 6d 75 6d 20 61 6e 64 20 |the mini|mum and |
|00001510| 6d 61 78 69 6d 75 6d 0d | 76 61 6c 75 65 73 20 6f |maximum.|values o|
|00001520| 66 20 61 6c 6c 20 73 61 | 6d 70 6c 65 73 20 69 6e |f all sa|mples in|
|00001530| 20 74 68 65 20 73 6f 75 | 6e 64 20 66 72 61 67 6d | the sou|nd fragm|
|00001540| 65 6e 74 2e 0d 5c 65 6e | 64 7b 66 75 6e 63 64 65 |ent..\en|d{funcde|
|00001550| 73 63 7d 0d 0d 5c 62 65 | 67 69 6e 7b 66 75 6e 63 |sc}..\be|gin{func|
|00001560| 64 65 73 63 7d 7b 6d 61 | 78 7d 7b 66 72 61 67 6d |desc}{ma|x}{fragm|
|00001570| 65 6e 74 5c 2c 20 77 69 | 64 74 68 7d 0d 54 68 69 |ent\, wi|dth}.Thi|
|00001580| 73 20 66 75 6e 63 74 69 | 6f 6e 20 72 65 74 75 72 |s functi|on retur|
|00001590| 6e 73 20 74 68 65 20 6d | 61 78 69 6d 75 6d 20 6f |ns the m|aximum o|
|000015a0| 66 20 74 68 65 20 7b 5c | 65 6d 20 61 62 73 6f 6c |f the {\|em absol|
|000015b0| 75 74 65 20 76 61 6c 75 | 65 7d 20 6f 66 20 61 6c |ute valu|e} of al|
|000015c0| 6c 0d 73 61 6d 70 6c 65 | 73 20 69 6e 20 61 20 66 |l.sample|s in a f|
|000015d0| 72 61 67 6d 65 6e 74 2e | 0d 5c 65 6e 64 7b 66 75 |ragment.|.\end{fu|
|000015e0| 6e 63 64 65 73 63 7d 0d | 0d 5c 62 65 67 69 6e 7b |ncdesc}.|.\begin{|
|000015f0| 66 75 6e 63 64 65 73 63 | 7d 7b 6d 61 78 70 70 7d |funcdesc|}{maxpp}|
|00001600| 7b 66 72 61 67 6d 65 6e | 74 5c 2c 20 77 69 64 74 |{fragmen|t\, widt|
|00001610| 68 7d 0d 54 68 69 73 20 | 66 75 6e 63 74 69 6f 6e |h}.This |function|
|00001620| 20 72 65 74 75 72 6e 73 | 20 74 68 65 20 6d 61 78 | returns| the max|
|00001630| 69 6d 75 6d 20 70 65 61 | 6b 2d 70 65 61 6b 20 76 |imum pea|k-peak v|
|00001640| 61 6c 75 65 20 69 6e 20 | 74 68 65 20 73 6f 75 6e |alue in |the soun|
|00001650| 64 20 66 72 61 67 6d 65 | 6e 74 2e 0d 5c 65 6e 64 |d fragme|nt..\end|
|00001660| 7b 66 75 6e 63 64 65 73 | 63 7d 0d 0d 5c 62 65 67 |{funcdes|c}..\beg|
|00001670| 69 6e 7b 66 75 6e 63 64 | 65 73 63 7d 7b 6d 75 6c |in{funcd|esc}{mul|
|00001680| 7d 7b 66 72 61 67 6d 65 | 6e 74 5c 2c 20 77 69 64 |}{fragme|nt\, wid|
|00001690| 74 68 5c 2c 20 66 61 63 | 74 6f 72 7d 0d 4d 75 6c |th\, fac|tor}.Mul|
|000016a0| 20 72 65 74 75 72 6e 73 | 20 61 20 66 72 61 67 6d | returns| a fragm|
|000016b0| 65 6e 74 20 74 68 61 74 | 20 68 61 73 20 61 6c 6c |ent that| has all|
|000016c0| 20 73 61 6d 70 6c 65 73 | 20 69 6e 20 74 68 65 20 | samples| in the |
|000016d0| 6f 72 69 67 69 6e 61 6c | 20 66 72 61 6d 67 65 6e |original| framgen|
|000016e0| 74 0d 6d 75 6c 74 69 70 | 6c 69 65 64 20 62 79 20 |t.multip|lied by |
|000016f0| 74 68 65 20 66 6c 6f 61 | 74 69 6e 67 2d 70 6f 69 |the floa|ting-poi|
|00001700| 6e 74 20 76 61 6c 75 65 | 20 5c 76 61 72 7b 66 61 |nt value| \var{fa|
|00001710| 63 74 6f 72 7d 2e 20 4f | 76 65 72 66 6c 6f 77 20 |ctor}. O|verflow |
|00001720| 69 73 0d 73 69 6c 65 6e | 74 6c 79 20 69 67 6e 6f |is.silen|tly igno|
|00001730| 72 65 64 2e 0d 5c 65 6e | 64 7b 66 75 6e 63 64 65 |red..\en|d{funcde|
|00001740| 73 63 7d 0d 0d 5c 62 65 | 67 69 6e 7b 66 75 6e 63 |sc}..\be|gin{func|
|00001750| 64 65 73 63 7d 7b 72 65 | 76 65 72 73 65 7d 7b 66 |desc}{re|verse}{f|
|00001760| 72 61 67 6d 65 6e 74 5c | 2c 20 77 69 64 74 68 7d |ragment\|, width}|
|00001770| 0d 54 68 69 73 20 66 75 | 6e 63 74 69 6f 6e 20 72 |.This fu|nction r|
|00001780| 65 76 65 72 73 65 73 20 | 74 68 65 20 73 61 6d 70 |everses |the samp|
|00001790| 6c 65 73 20 69 6e 20 61 | 20 66 72 61 67 6d 65 6e |les in a| fragmen|
|000017a0| 74 20 61 6e 64 20 72 65 | 74 75 72 6e 73 20 74 68 |t and re|turns th|
|000017b0| 65 0d 6d 6f 64 69 66 69 | 65 64 20 66 72 61 67 6d |e.modifi|ed fragm|
|000017c0| 65 6e 74 2e 0d 5c 65 6e | 64 7b 66 75 6e 63 64 65 |ent..\en|d{funcde|
|000017d0| 73 63 7d 0d 0d 5c 62 65 | 67 69 6e 7b 66 75 6e 63 |sc}..\be|gin{func|
|000017e0| 64 65 73 63 7d 7b 74 6f | 6d 6f 6e 6f 7d 7b 66 72 |desc}{to|mono}{fr|
|000017f0| 61 67 6d 65 6e 74 5c 2c | 20 77 69 64 74 68 5c 2c |agment\,| width\,|
|00001800| 20 6c 66 61 63 74 6f 72 | 5c 2c 20 72 66 61 63 74 | lfactor|\, rfact|
|00001810| 6f 72 7d 20 0d 54 68 69 | 73 20 66 75 6e 63 74 69 |or} .Thi|s functi|
|00001820| 6f 6e 20 63 6f 6e 76 65 | 72 74 73 20 61 20 73 74 |on conve|rts a st|
|00001830| 65 72 65 6f 20 66 72 61 | 67 6d 65 6e 74 20 74 6f |ereo fra|gment to|
|00001840| 20 61 20 6d 6f 6e 6f 20 | 66 72 61 67 6d 65 6e 74 | a mono |fragment|
|00001850| 2e 20 54 68 65 20 6c 65 | 66 74 0d 63 68 61 6e 6e |. The le|ft.chann|
|00001860| 65 6c 20 69 73 20 6d 75 | 6c 74 69 70 6c 69 65 64 |el is mu|ltiplied|
|00001870| 20 62 79 20 5c 76 61 72 | 7b 6c 66 61 63 74 6f 72 | by \var|{lfactor|
|00001880| 7d 20 61 6e 64 20 74 68 | 65 20 72 69 67 68 74 20 |} and th|e right |
|00001890| 63 68 61 6e 6e 65 6c 20 | 62 79 0d 5c 76 61 72 7b |channel |by.\var{|
|000018a0| 72 66 61 63 74 6f 72 7d | 20 62 65 66 6f 72 65 20 |rfactor}| before |
|000018b0| 61 64 64 69 6e 67 20 74 | 68 65 20 74 77 6f 20 63 |adding t|he two c|
|000018c0| 68 61 6e 6e 65 6c 73 20 | 74 6f 20 67 69 76 65 20 |hannels |to give |
|000018d0| 61 20 6d 6f 6e 6f 20 73 | 69 67 6e 61 6c 2e 0d 5c |a mono s|ignal..\|
|000018e0| 65 6e 64 7b 66 75 6e 63 | 64 65 73 63 7d 0d 0d 5c |end{func|desc}..\|
|000018f0| 62 65 67 69 6e 7b 66 75 | 6e 63 64 65 73 63 7d 7b |begin{fu|ncdesc}{|
|00001900| 74 6f 73 74 65 72 65 6f | 7d 7b 66 72 61 67 6d 65 |tostereo|}{fragme|
|00001910| 6e 74 5c 2c 20 77 69 64 | 74 68 5c 2c 20 6c 66 61 |nt\, wid|th\, lfa|
|00001920| 63 74 6f 72 5c 2c 20 72 | 66 61 63 74 6f 72 7d 0d |ctor\, r|factor}.|
|00001930| 54 68 69 73 20 66 75 6e | 63 74 69 6f 6e 20 67 65 |This fun|ction ge|
|00001940| 6e 65 72 61 74 65 73 20 | 61 20 73 74 65 72 65 6f |nerates |a stereo|
|00001950| 20 66 72 61 67 6d 65 6e | 74 20 66 72 6f 6d 20 61 | fragmen|t from a|
|00001960| 20 6d 6f 6e 6f 20 66 72 | 61 67 6d 65 6e 74 2e 20 | mono fr|agment. |
|00001970| 45 61 63 68 0d 70 61 69 | 72 20 6f 66 20 73 61 6d |Each.pai|r of sam|
|00001980| 70 6c 65 73 20 69 6e 20 | 74 68 65 20 73 74 65 72 |ples in |the ster|
|00001990| 65 6f 20 66 72 61 67 6d | 65 6e 74 20 61 72 65 20 |eo fragm|ent are |
|000019a0| 63 6f 6d 70 75 74 65 64 | 20 66 72 6f 6d 20 74 68 |computed| from th|
|000019b0| 65 20 6d 6f 6e 6f 0d 73 | 61 6d 70 6c 65 2c 20 77 |e mono.s|ample, w|
|000019c0| 68 65 72 65 62 79 20 6c | 65 66 74 20 63 68 61 6e |hereby l|eft chan|
|000019d0| 6e 65 6c 20 73 61 6d 70 | 6c 65 73 20 61 72 65 20 |nel samp|les are |
|000019e0| 6d 75 6c 74 69 70 6c 69 | 65 64 20 62 79 20 5c 76 |multipli|ed by \v|
|000019f0| 61 72 7b 6c 66 61 63 74 | 6f 72 7d 0d 61 6e 64 20 |ar{lfact|or}.and |
|00001a00| 72 69 67 68 74 20 63 68 | 61 6e 6e 65 6c 20 73 61 |right ch|annel sa|
|00001a10| 6d 70 6c 65 73 20 62 79 | 20 5c 76 61 72 7b 72 66 |mples by| \var{rf|
|00001a20| 61 63 74 6f 72 7d 2e 0d | 5c 65 6e 64 7b 66 75 6e |actor}..|\end{fun|
|00001a30| 63 64 65 73 63 7d 0d 0d | 5c 62 65 67 69 6e 7b 66 |cdesc}..|\begin{f|
|00001a40| 75 6e 63 64 65 73 63 7d | 7b 6d 75 6c 7d 7b 66 72 |uncdesc}|{mul}{fr|
|00001a50| 61 67 6d 65 6e 74 5c 2c | 20 77 69 64 74 68 5c 2c |agment\,| width\,|
|00001a60| 20 66 61 63 74 6f 72 7d | 0d 4d 75 6c 20 72 65 74 | factor}|.Mul ret|
|00001a70| 75 72 6e 73 20 61 20 66 | 72 61 67 6d 65 6e 74 20 |urns a f|ragment |
|00001a80| 74 68 61 74 20 68 61 73 | 20 61 6c 6c 20 73 61 6d |that has| all sam|
|00001a90| 70 6c 65 73 20 69 6e 20 | 74 68 65 20 6f 72 69 67 |ples in |the orig|
|00001aa0| 69 6e 61 6c 20 66 72 61 | 6d 67 65 6e 74 0d 6d 75 |inal fra|mgent.mu|
|00001ab0| 6c 74 69 70 6c 69 65 64 | 20 62 79 20 74 68 65 20 |ltiplied| by the |
|00001ac0| 66 6c 6f 61 74 69 6e 67 | 2d 70 6f 69 6e 74 20 76 |floating|-point v|
|00001ad0| 61 6c 75 65 20 5c 76 61 | 72 7b 66 61 63 74 6f 72 |alue \va|r{factor|
|00001ae0| 7d 2e 20 4f 76 65 72 66 | 6c 6f 77 20 69 73 0d 73 |}. Overf|low is.s|
|00001af0| 69 6c 65 6e 74 6c 79 20 | 69 67 6e 6f 72 65 64 2e |ilently |ignored.|
|00001b00| 0d 5c 65 6e 64 7b 66 75 | 6e 63 64 65 73 63 7d 0d |.\end{fu|ncdesc}.|
|00001b10| 0d 5c 62 65 67 69 6e 7b | 66 75 6e 63 64 65 73 63 |.\begin{|funcdesc|
|00001b20| 7d 7b 72 6d 73 7d 7b 66 | 72 61 67 6d 65 6e 74 5c |}{rms}{f|ragment\|
|00001b30| 2c 20 77 69 64 74 68 5c | 2c 20 66 61 63 74 6f 72 |, width\|, factor|
|00001b40| 7d 0d 52 65 74 75 72 6e | 73 20 74 68 65 20 72 6f |}.Return|s the ro|
|00001b50| 6f 74 2d 6d 65 61 6e 2d | 73 71 75 61 72 65 20 6f |ot-mean-|square o|
|00001b60| 66 20 74 68 65 20 66 72 | 61 67 6d 65 6e 74 2c 20 |f the fr|agment, |
|00001b70| 69 2e 65 2e 0d 5c 69 66 | 74 65 78 69 0d 74 68 65 |i.e..\if|texi.the|
|00001b80| 20 73 71 75 61 72 65 20 | 72 6f 6f 74 20 6f 66 20 | square |root of |
|00001b90| 74 68 65 20 71 75 6f 74 | 69 65 6e 74 20 6f 66 20 |the quot|ient of |
|00001ba0| 74 68 65 20 73 75 6d 20 | 6f 66 20 61 6c 6c 20 73 |the sum |of all s|
|00001bb0| 71 75 61 72 65 64 20 73 | 61 6d 70 6c 65 20 76 61 |quared s|ample va|
|00001bc0| 6c 75 65 2c 0d 64 69 76 | 69 64 65 64 20 62 79 20 |lue,.div|ided by |
|00001bd0| 74 68 65 20 73 75 6d 62 | 65 72 20 6f 66 20 73 61 |the sumb|er of sa|
|00001be0| 6d 70 6c 65 73 2e 0d 5c | 65 6c 73 65 0d 25 20 69 |mples..\|else.% i|
|00001bf0| 6e 20 65 71 6e 3a 20 73 | 71 72 74 20 7b 20 73 75 |n eqn: s|qrt { su|
|00001c00| 6d 20 53 20 73 75 62 20 | 69 20 73 75 70 20 32 20 |m S sub |i sup 2 |
|00001c10| 20 6f 76 65 72 20 6e 20 | 7d 0d 5c 62 65 67 69 6e | over n |}.\begin|
|00001c20| 7b 64 69 73 70 6c 61 79 | 6d 61 74 68 7d 0d 5c 63 |{display|math}.\c|
|00001c30| 61 74 63 6f 64 65 60 5f | 3d 38 0d 5c 73 71 72 74 |atcode`_|=8.\sqrt|
|00001c40| 7b 5c 66 72 61 63 7b 5c | 73 75 6d 7b 7b 53 5f 7b |{\frac{\|sum{{S_{|
|00001c50| 69 7d 7d 5e 7b 32 7d 7d | 7d 7b 6e 7d 7d 0d 5c 65 |i}}^{2}}|}{n}}.\e|
|00001c60| 6e 64 7b 64 69 73 70 6c | 61 79 6d 61 74 68 7d 0d |nd{displ|aymath}.|
|00001c70| 5c 66 69 0d 54 68 69 73 | 20 69 73 20 61 20 6d 65 |\fi.This| is a me|
|00001c80| 61 73 75 72 65 20 6f 66 | 20 74 68 65 20 70 6f 77 |asure of| the pow|
|00001c90| 65 72 20 69 6e 20 61 6e | 20 61 75 64 69 6f 20 73 |er in an| audio s|
|00001ca0| 69 67 6e 61 6c 2e 0d 5c | 65 6e 64 7b 66 75 6e 63 |ignal..\|end{func|
|00001cb0| 64 65 73 63 7d 0d 0d 5c | 62 65 67 69 6e 7b 66 75 |desc}..\|begin{fu|
|00001cc0| 6e 63 64 65 73 63 7d 7b | 75 6c 61 77 32 6c 69 6e |ncdesc}{|ulaw2lin|
|00001cd0| 7d 7b 66 72 61 67 6d 65 | 6e 74 5c 2c 20 77 69 64 |}{fragme|nt\, wid|
|00001ce0| 74 68 7d 0d 54 68 69 73 | 20 66 75 6e 63 74 69 6f |th}.This| functio|
|00001cf0| 6e 20 63 6f 6e 76 65 72 | 74 73 20 73 6f 75 6e 64 |n conver|ts sound|
|00001d00| 20 66 72 61 67 6d 65 6e | 74 73 20 69 6e 20 55 4c | fragmen|ts in UL|
|00001d10| 41 57 20 65 6e 63 6f 64 | 69 6e 67 20 74 6f 20 6c |AW encod|ing to l|
|00001d20| 69 6e 65 61 72 6c 79 0d | 65 6e 63 6f 64 65 64 20 |inearly.|encoded |
|00001d30| 73 6f 75 6e 64 20 66 72 | 61 67 6d 65 6e 74 73 2e |sound fr|agments.|
|00001d40| 20 55 4c 41 57 20 65 6e | 63 6f 64 69 6e 67 20 61 | ULAW en|coding a|
|00001d50| 6c 77 61 79 73 20 75 73 | 65 73 20 38 20 62 69 74 |lways us|es 8 bit|
|00001d60| 73 20 73 61 6d 70 6c 65 | 73 2c 20 73 6f 0d 5c 76 |s sample|s, so.\v|
|00001d70| 61 72 7b 77 69 64 74 68 | 7d 20 72 65 66 65 72 73 |ar{width|} refers|
|00001d80| 20 6f 6e 6c 79 20 74 6f | 20 74 68 65 20 73 61 6d | only to| the sam|
|00001d90| 70 6c 65 20 77 69 64 74 | 68 20 6f 66 20 74 68 65 |ple widt|h of the|
|00001da0| 20 6f 75 74 70 75 74 20 | 66 72 61 67 6d 65 6e 74 | output |fragment|
|00001db0| 20 68 65 72 65 2e 0d 5c | 65 6e 64 7b 66 75 6e 63 | here..\|end{func|
|00001dc0| 64 65 73 63 7d 0d 0d 4e | 6f 74 65 20 74 68 61 74 |desc}..N|ote that|
|00001dd0| 20 6f 70 65 72 61 74 69 | 6f 6e 73 20 73 75 63 68 | operati|ons such|
|00001de0| 20 61 73 20 5c 63 6f 64 | 65 7b 6d 75 6c 7d 20 6f | as \cod|e{mul} o|
|00001df0| 72 20 5c 63 6f 64 65 7b | 6d 61 78 7d 20 6d 61 6b |r \code{|max} mak|
|00001e00| 65 20 6e 6f 0d 64 69 73 | 74 69 6e 63 74 69 6f 6e |e no.dis|tinction|
|00001e10| 20 62 65 74 77 65 65 6e | 20 6d 6f 6e 6f 20 61 6e | between| mono an|
|00001e20| 64 20 73 74 65 72 65 6f | 20 66 72 61 67 6d 65 6e |d stereo| fragmen|
|00001e30| 74 73 2c 20 69 2e 65 2e | 20 61 6c 6c 20 73 61 6d |ts, i.e.| all sam|
|00001e40| 70 6c 65 73 20 61 72 65 | 0d 74 72 65 61 74 65 64 |ples are|.treated|
|00001e50| 20 65 71 75 61 6c 2e 20 | 20 49 66 20 74 68 69 73 | equal. | If this|
|00001e60| 20 69 73 20 61 20 70 72 | 6f 62 6c 65 6d 20 74 68 | is a pr|oblem th|
|00001e70| 65 20 73 74 65 72 65 6f | 20 66 72 61 67 6d 65 6e |e stereo| fragmen|
|00001e80| 74 20 73 68 6f 75 6c 64 | 20 62 65 20 73 70 6c 69 |t should| be spli|
|00001e90| 74 0d 69 6e 74 6f 20 74 | 77 6f 20 6d 6f 6e 6f 20 |t.into t|wo mono |
|00001ea0| 66 72 61 67 6d 65 6e 74 | 73 20 66 69 72 73 74 20 |fragment|s first |
|00001eb0| 61 6e 64 20 72 65 63 6f | 6d 62 69 6e 65 64 20 6c |and reco|mbined l|
|00001ec0| 61 74 65 72 2e 20 20 48 | 65 72 65 20 69 73 20 61 |ater. H|ere is a|
|00001ed0| 6e 20 65 78 61 6d 70 6c | 65 0d 6f 66 20 68 6f 77 |n exampl|e.of how|
|00001ee0| 20 74 6f 20 64 6f 20 74 | 68 61 74 3a 0d 5c 62 63 | to do t|hat:.\bc|
|00001ef0| 6f 64 65 5c 62 65 67 69 | 6e 7b 76 65 72 62 61 74 |ode\begi|n{verbat|
|00001f00| 69 6d 7d 0d 64 65 66 20 | 6d 75 6c 5f 73 74 65 72 |im}.def |mul_ster|
|00001f10| 65 6f 28 73 61 6d 70 6c | 65 2c 20 77 69 64 74 68 |eo(sampl|e, width|
|00001f20| 2c 20 6c 66 61 63 74 6f | 72 2c 20 72 66 61 63 74 |, lfacto|r, rfact|
|00001f30| 6f 72 29 3a 0d 20 20 20 | 20 6c 73 61 6d 70 6c 65 |or):. | lsample|
|00001f40| 20 3d 20 61 75 64 69 6f | 6f 70 2e 74 6f 6d 6f 6e | = audio|op.tomon|
|00001f50| 6f 28 73 61 6d 70 6c 65 | 2c 20 77 69 64 74 68 2c |o(sample|, width,|
|00001f60| 20 31 2c 20 30 29 0d 20 | 20 20 20 72 73 61 6d 70 | 1, 0). | rsamp|
|00001f70| 6c 65 20 3d 20 61 75 64 | 69 6f 6f 70 2e 74 6f 6d |le = aud|ioop.tom|
|00001f80| 6f 6e 6f 28 73 61 6d 70 | 6c 65 2c 20 77 69 64 74 |ono(samp|le, widt|
|00001f90| 68 2c 20 30 2c 20 31 29 | 0d 20 20 20 20 6c 73 61 |h, 0, 1)|. lsa|
|00001fa0| 6d 70 6c 65 20 3d 20 61 | 75 64 69 6f 6f 70 2e 6d |mple = a|udioop.m|
|00001fb0| 75 6c 28 73 61 6d 70 6c | 65 2c 20 77 69 64 74 68 |ul(sampl|e, width|
|00001fc0| 2c 20 6c 66 61 63 74 6f | 72 29 0d 20 20 20 20 72 |, lfacto|r). r|
|00001fd0| 73 61 6d 70 6c 65 20 3d | 20 61 75 64 69 6f 6f 70 |sample =| audioop|
|00001fe0| 2e 6d 75 6c 28 73 61 6d | 70 6c 65 2c 20 77 69 64 |.mul(sam|ple, wid|
|00001ff0| 74 68 2c 20 72 66 61 63 | 74 6f 72 29 0d 20 20 20 |th, rfac|tor). |
|00002000| 20 6c 73 61 6d 70 6c 65 | 20 3d 20 61 75 64 69 6f | lsample| = audio|
|00002010| 6f 70 2e 74 6f 73 74 65 | 72 65 6f 28 6c 73 61 6d |op.toste|reo(lsam|
|00002020| 70 6c 65 2c 20 77 69 64 | 74 68 2c 20 31 2c 20 30 |ple, wid|th, 1, 0|
|00002030| 29 0d 20 20 20 20 72 73 | 61 6d 70 6c 65 20 3d 20 |). rs|ample = |
|00002040| 61 75 64 69 6f 6f 70 2e | 74 6f 73 74 65 72 65 6f |audioop.|tostereo|
|00002050| 28 72 73 61 6d 70 6c 65 | 2c 20 77 69 64 74 68 2c |(rsample|, width,|
|00002060| 20 30 2c 20 31 29 0d 20 | 20 20 20 72 65 74 75 72 | 0, 1). | retur|
|00002070| 6e 20 61 75 64 69 6f 6f | 70 2e 61 64 64 28 6c 73 |n audioo|p.add(ls|
|00002080| 61 6d 70 6c 65 2c 20 72 | 73 61 6d 70 6c 65 2c 20 |ample, r|sample, |
|00002090| 77 69 64 74 68 29 0d 5c | 65 6e 64 7b 76 65 72 62 |width).\|end{verb|
|000020a0| 61 74 69 6d 7d 5c 65 63 | 6f 64 65 0d 0d 49 66 20 |atim}\ec|ode..If |
|000020b0| 79 6f 75 20 75 73 65 20 | 74 68 65 20 41 44 50 43 |you use |the ADPC|
|000020c0| 4d 20 63 6f 64 65 72 20 | 74 6f 20 62 75 69 6c 64 |M coder |to build|
|000020d0| 20 6e 65 74 77 6f 72 6b | 20 70 61 63 6b 65 74 73 | network| packets|
|000020e0| 20 61 6e 64 20 79 6f 75 | 20 77 61 6e 74 20 79 6f | and you| want yo|
|000020f0| 75 72 0d 70 72 6f 74 6f | 63 6f 6c 20 74 6f 20 62 |ur.proto|col to b|
|00002100| 65 20 73 74 61 74 65 6c | 65 73 73 20 28 69 2e 65 |e statel|ess (i.e|
|00002110| 2e 20 74 6f 20 62 65 20 | 61 62 6c 65 20 74 6f 20 |. to be |able to |
|00002120| 74 6f 6c 65 72 61 74 65 | 20 70 61 63 6b 65 74 20 |tolerate| packet |
|00002130| 6c 6f 73 73 29 0d 79 6f | 75 20 73 68 6f 75 6c 64 |loss).yo|u should|
|00002140| 20 6e 6f 74 20 6f 6e 6c | 79 20 74 72 61 6e 73 6d | not onl|y transm|
|00002150| 69 74 20 74 68 65 20 64 | 61 74 61 20 62 75 74 20 |it the d|ata but |
|00002160| 61 6c 73 6f 20 74 68 65 | 20 73 74 61 74 65 2e 20 |also the| state. |
|00002170| 4e 6f 74 65 20 74 68 61 | 74 0d 79 6f 75 20 73 68 |Note tha|t.you sh|
|00002180| 6f 75 6c 64 20 73 65 6e | 64 20 74 68 65 20 5c 76 |ould sen|d the \v|
|00002190| 61 72 7b 69 6e 69 74 69 | 61 6c 7d 20 73 74 61 74 |ar{initi|al} stat|
|000021a0| 65 20 28 74 68 65 20 6f | 6e 65 20 79 6f 75 20 70 |e (the o|ne you p|
|000021b0| 61 73 73 65 64 20 74 6f | 0d 6c 69 6e 32 61 64 70 |assed to|.lin2adp|
|000021c0| 63 6d 29 20 61 6c 6f 6e | 67 20 74 6f 20 74 68 65 |cm) alon|g to the|
|000021d0| 20 64 65 63 6f 64 65 72 | 2c 20 6e 6f 74 20 74 68 | decoder|, not th|
|000021e0| 65 20 66 69 6e 61 6c 20 | 73 74 61 74 65 20 28 61 |e final |state (a|
|000021f0| 73 20 72 65 74 75 72 6e | 65 64 20 62 79 0d 74 68 |s return|ed by.th|
|00002200| 65 20 63 6f 64 65 72 29 | 2e 20 49 66 20 79 6f 75 |e coder)|. If you|
|00002210| 20 77 61 6e 74 20 74 6f | 20 75 73 65 20 5c 63 6f | want to| use \co|
|00002220| 64 65 7b 73 74 72 75 63 | 74 7d 20 74 6f 20 73 74 |de{struc|t} to st|
|00002230| 6f 72 65 20 74 68 65 20 | 73 74 61 74 65 20 69 6e |ore the |state in|
|00002240| 0d 62 69 6e 61 72 79 20 | 79 6f 75 20 63 61 6e 20 |.binary |you can |
|00002250| 63 6f 64 65 20 74 68 65 | 20 66 69 72 73 74 20 65 |code the| first e|
|00002260| 6c 65 6d 65 6e 74 20 28 | 74 68 65 20 70 72 65 64 |lement (|the pred|
|00002270| 69 63 74 65 64 20 76 61 | 6c 75 65 29 20 69 6e 20 |icted va|lue) in |
|00002280| 31 36 20 62 69 74 73 0d | 61 6e 64 20 74 68 65 20 |16 bits.|and the |
|00002290| 73 65 63 6f 6e 64 20 28 | 74 68 65 20 64 65 6c 74 |second (|the delt|
|000022a0| 61 20 69 6e 64 65 78 29 | 20 69 6e 20 38 2e 0d 0d |a index)| in 8...|
|000022b0| 54 68 65 20 41 44 50 43 | 4d 20 63 6f 64 65 72 73 |The ADPC|M coders|
|000022c0| 20 68 61 76 65 20 6e 65 | 76 65 72 20 62 65 65 6e | have ne|ver been|
|000022d0| 20 74 72 69 65 64 20 61 | 67 61 69 6e 73 74 20 6f | tried a|gainst o|
|000022e0| 74 68 65 72 20 41 44 50 | 43 4d 20 63 6f 64 65 72 |ther ADP|CM coder|
|000022f0| 73 2c 0d 6f 6e 6c 79 20 | 61 67 61 69 6e 73 74 20 |s,.only |against |
|00002300| 74 68 65 6d 73 65 6c 76 | 65 73 2e 20 49 74 20 63 |themselv|es. It c|
|00002310| 6f 75 6c 64 20 77 65 6c | 6c 20 62 65 20 74 68 61 |ould wel|l be tha|
|00002320| 74 20 49 20 6d 69 73 69 | 6e 74 65 72 70 72 65 74 |t I misi|nterpret|
|00002330| 65 64 20 74 68 65 0d 73 | 74 61 6e 64 61 72 64 73 |ed the.s|tandards|
|00002340| 20 69 6e 20 77 68 69 63 | 68 20 63 61 73 65 20 74 | in whic|h case t|
|00002350| 68 65 79 20 77 69 6c 6c | 20 6e 6f 74 20 62 65 20 |hey will| not be |
|00002360| 69 6e 74 65 72 6f 70 65 | 72 61 62 6c 65 20 77 69 |interope|rable wi|
|00002370| 74 68 20 74 68 65 0d 72 | 65 73 70 65 63 74 69 76 |th the.r|espectiv|
|00002380| 65 20 73 74 61 6e 64 61 | 72 64 73 2e 0d 0d 54 68 |e standa|rds...Th|
|00002390| 65 20 5c 63 6f 64 65 7b | 66 69 6e 64 2e 2e 2e 7d |e \code{|find...}|
|000023a0| 20 72 6f 75 74 69 6e 65 | 73 20 6d 69 67 68 74 20 | routine|s might |
|000023b0| 6c 6f 6f 6b 20 61 20 62 | 69 74 20 66 75 6e 6e 79 |look a b|it funny|
|000023c0| 20 61 74 20 66 69 72 73 | 74 20 73 69 67 68 74 2e | at firs|t sight.|
|000023d0| 0d 54 68 65 79 20 61 72 | 65 20 70 72 69 6d 61 72 |.They ar|e primar|
|000023e0| 69 6c 79 20 6d 65 61 6e | 74 20 66 6f 72 20 64 6f |ily mean|t for do|
|000023f0| 69 6e 67 20 65 63 68 6f | 20 63 61 6e 63 65 6c 6c |ing echo| cancell|
|00002400| 61 74 69 6f 6e 2e 20 41 | 20 72 65 61 73 6f 6e 61 |ation. A| reasona|
|00002410| 62 6c 79 0d 66 61 73 74 | 20 77 61 79 20 74 6f 20 |bly.fast| way to |
|00002420| 64 6f 20 74 68 69 73 20 | 69 73 20 74 6f 20 70 69 |do this |is to pi|
|00002430| 63 6b 20 74 68 65 20 6d | 6f 73 74 20 65 6e 65 72 |ck the m|ost ener|
|00002440| 67 65 74 69 63 20 70 69 | 65 63 65 20 6f 66 20 74 |getic pi|ece of t|
|00002450| 68 65 20 6f 75 74 70 75 | 74 0d 73 61 6d 70 6c 65 |he outpu|t.sample|
|00002460| 2c 20 6c 6f 63 61 74 65 | 20 74 68 61 74 20 69 6e |, locate| that in|
|00002470| 20 74 68 65 20 69 6e 70 | 75 74 20 73 61 6d 70 6c | the inp|ut sampl|
|00002480| 65 20 61 6e 64 20 73 75 | 62 74 72 61 63 74 20 74 |e and su|btract t|
|00002490| 68 65 20 77 68 6f 6c 65 | 20 6f 75 74 70 75 74 0d |he whole| output.|
|000024a0| 73 61 6d 70 6c 65 20 66 | 72 6f 6d 20 74 68 65 20 |sample f|rom the |
|000024b0| 69 6e 70 75 74 20 73 61 | 6d 70 6c 65 3a 0d 5c 62 |input sa|mple:.\b|
|000024c0| 63 6f 64 65 5c 62 65 67 | 69 6e 7b 76 65 72 62 61 |code\beg|in{verba|
|000024d0| 74 69 6d 7d 0d 64 65 66 | 20 65 63 68 6f 63 61 6e |tim}.def| echocan|
|000024e0| 63 65 6c 28 6f 75 74 70 | 75 74 64 61 74 61 2c 20 |cel(outp|utdata, |
|000024f0| 69 6e 70 75 74 64 61 74 | 61 29 3a 0d 20 20 20 20 |inputdat|a):. |
|00002500| 70 6f 73 20 3d 20 61 75 | 64 69 6f 6f 70 2e 66 69 |pos = au|dioop.fi|
|00002510| 6e 64 6d 61 78 28 6f 75 | 74 70 75 74 64 61 74 61 |ndmax(ou|tputdata|
|00002520| 2c 20 38 30 30 29 20 20 | 20 20 23 20 6f 6e 65 20 |, 800) | # one |
|00002530| 74 65 6e 74 68 20 73 65 | 63 6f 6e 64 0d 20 20 20 |tenth se|cond. |
|00002540| 20 6f 75 74 5f 74 65 73 | 74 20 3d 20 6f 75 74 70 | out_tes|t = outp|
|00002550| 75 74 64 61 74 61 5b 70 | 6f 73 2a 32 3a 5d 0d 20 |utdata[p|os*2:]. |
|00002560| 20 20 20 69 6e 5f 74 65 | 73 74 20 3d 20 69 6e 70 | in_te|st = inp|
|00002570| 75 74 64 61 74 61 5b 70 | 6f 73 2a 32 3a 5d 0d 20 |utdata[p|os*2:]. |
|00002580| 20 20 20 69 70 6f 73 2c | 20 66 61 63 74 6f 72 20 | ipos,| factor |
|00002590| 3d 20 61 75 64 69 6f 6f | 70 2e 66 69 6e 64 66 69 |= audioo|p.findfi|
|000025a0| 74 28 69 6e 5f 74 65 73 | 74 2c 20 6f 75 74 5f 74 |t(in_tes|t, out_t|
|000025b0| 65 73 74 29 0d 20 20 20 | 20 23 20 4f 70 74 69 6f |est). | # Optio|
|000025c0| 6e 61 6c 20 28 66 6f 72 | 20 62 65 74 74 65 72 20 |nal (for| better |
|000025d0| 63 61 6e 63 65 6c 6c 61 | 74 69 6f 6e 29 3a 0d 20 |cancella|tion):. |
|000025e0| 20 20 20 23 20 66 61 63 | 74 6f 72 20 3d 20 61 75 | # fac|tor = au|
|000025f0| 64 69 6f 6f 70 2e 66 69 | 6e 64 66 61 63 74 6f 72 |dioop.fi|ndfactor|
|00002600| 28 69 6e 5f 74 65 73 74 | 5b 69 70 6f 73 2a 32 3a |(in_test|[ipos*2:|
|00002610| 69 70 6f 73 2a 32 2b 6c | 65 6e 28 6f 75 74 5f 74 |ipos*2+l|en(out_t|
|00002620| 65 73 74 29 5d 2c 20 0d | 20 20 20 20 23 20 20 20 |est)], .| # |
|00002630| 20 20 20 20 20 20 20 20 | 20 20 20 6f 75 74 5f 74 | | out_t|
|00002640| 65 73 74 29 0d 20 20 20 | 20 70 72 65 66 69 6c 6c |est). | prefill|
|00002650| 20 3d 20 27 5c 30 27 2a | 28 70 6f 73 2b 69 70 6f | = '\0'*|(pos+ipo|
|00002660| 73 29 2a 32 0d 20 20 20 | 20 70 6f 73 74 66 69 6c |s)*2. | postfil|
|00002670| 6c 20 3d 20 27 5c 30 27 | 2a 28 6c 65 6e 28 69 6e |l = '\0'|*(len(in|
|00002680| 70 75 74 64 61 74 61 29 | 2d 6c 65 6e 28 70 72 65 |putdata)|-len(pre|
|00002690| 66 69 6c 6c 29 2d 6c 65 | 6e 28 6f 75 74 70 75 74 |fill)-le|n(output|
|000026a0| 64 61 74 61 29 29 0d 20 | 20 20 20 6f 75 74 70 75 |data)). | outpu|
|000026b0| 74 64 61 74 61 20 3d 20 | 70 72 65 66 69 6c 6c 20 |tdata = |prefill |
|000026c0| 2b 20 61 75 64 69 6f 6f | 70 2e 6d 75 6c 28 6f 75 |+ audioo|p.mul(ou|
|000026d0| 74 70 75 74 64 61 74 61 | 2c 32 2c 2d 66 61 63 74 |tputdata|,2,-fact|
|000026e0| 6f 72 29 20 2b 20 70 6f | 73 74 66 69 6c 6c 0d 20 |or) + po|stfill. |
|000026f0| 20 20 20 72 65 74 75 72 | 6e 20 61 75 64 69 6f 6f | retur|n audioo|
|00002700| 70 2e 61 64 64 28 69 6e | 70 75 74 64 61 74 61 2c |p.add(in|putdata,|
|00002710| 20 6f 75 74 70 75 74 64 | 61 74 61 2c 20 32 29 0d | outputd|ata, 2).|
|00002720| 5c 65 6e 64 7b 76 65 72 | 62 61 74 69 6d 7d 5c 65 |\end{ver|batim}\e|
|00002730| 63 6f 64 65 0d | |code. | |
+--------+-------------------------+-------------------------+--------+--------+