home *** CD-ROM | disk | FTP | other *** search
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: tex
Confidence | Program | Detection | Match Type | Support
|
---|
100%
| dexvert
| LaTeX Document (document/latex)
| magic
| Supported |
1%
| dexvert
| Text File (text/txt)
| fallback
| Supported |
100%
| file
| LaTeX document text
| default
| |
99%
| file
| Python script text executable
| default (weak)
| |
98%
| file
| LaTeX document, ASCII text
| default
| |
100%
| checkBytes
| Printable ASCII
| default
| |
100%
| perlTextCheck
| Likely Text (Perl)
| default
| |
100%
| siegfried
| fmt/281 LaTeX (Subdocument)
| default
| |
100%
| detectItEasy
| Format: plain text[LF]
| default (weak)
|
|
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 4d 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 0a 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 0a 0a 54 68 65 20 5c | 63 6f 64 65 7b 61 75 64 |}..The \|code{aud|
|00000050| 69 6f 6f 70 7d 20 6d 6f | 64 75 6c 65 20 63 6f 6e |ioop} mo|dule con|
|00000060| 74 61 69 6e 73 20 73 6f | 6d 65 20 75 73 65 66 75 |tains so|me usefu|
|00000070| 6c 20 6f 70 65 72 61 74 | 69 6f 6e 73 20 6f 6e 20 |l operat|ions on |
|00000080| 73 6f 75 6e 64 20 66 72 | 61 67 6d 65 6e 74 73 2e |sound fr|agments.|
|00000090| 0a 49 74 20 6f 70 65 72 | 61 74 65 73 20 6f 6e 20 |.It oper|ates on |
|000000a0| 73 6f 75 6e 64 20 66 72 | 61 67 6d 65 6e 74 73 20 |sound fr|agments |
|000000b0| 63 6f 6e 73 69 73 74 69 | 6e 67 20 6f 66 20 73 69 |consisti|ng of si|
|000000c0| 67 6e 65 64 20 69 6e 74 | 65 67 65 72 20 73 61 6d |gned int|eger sam|
|000000d0| 70 6c 65 73 0a 38 2c 20 | 31 36 20 6f 72 20 33 32 |ples.8, |16 or 32|
|000000e0| 20 62 69 74 73 20 77 69 | 64 65 2c 20 73 74 6f 72 | bits wi|de, stor|
|000000f0| 65 64 20 69 6e 20 50 79 | 74 68 6f 6e 20 73 74 72 |ed in Py|thon str|
|00000100| 69 6e 67 73 2e 20 20 54 | 68 69 73 20 69 73 20 74 |ings. T|his is t|
|00000110| 68 65 20 73 61 6d 65 0a | 66 6f 72 6d 61 74 20 61 |he same.|format a|
|00000120| 73 20 75 73 65 64 20 62 | 79 20 74 68 65 20 5c 63 |s used b|y the \c|
|00000130| 6f 64 65 7b 61 6c 7d 20 | 61 6e 64 20 5c 63 6f 64 |ode{al} |and \cod|
|00000140| 65 7b 73 75 6e 61 75 64 | 69 6f 64 65 76 7d 20 6d |e{sunaud|iodev} m|
|00000150| 6f 64 75 6c 65 73 2e 20 | 20 41 6c 6c 0a 73 63 61 |odules. | All.sca|
|00000160| 6c 61 72 20 69 74 65 6d | 73 20 61 72 65 20 69 6e |lar item|s are in|
|00000170| 74 65 67 65 72 73 2c 20 | 75 6e 6c 65 73 73 20 73 |tegers, |unless s|
|00000180| 70 65 63 69 66 69 65 64 | 20 6f 74 68 65 72 77 69 |pecified| otherwi|
|00000190| 73 65 2e 0a 0a 41 20 66 | 65 77 20 6f 66 20 74 68 |se...A f|ew of th|
|000001a0| 65 20 6d 6f 72 65 20 63 | 6f 6d 70 6c 69 63 61 74 |e more c|omplicat|
|000001b0| 65 64 20 6f 70 65 72 61 | 74 69 6f 6e 73 20 6f 6e |ed opera|tions on|
|000001c0| 6c 79 20 74 61 6b 65 20 | 31 36 2d 62 69 74 20 73 |ly take |16-bit s|
|000001d0| 61 6d 70 6c 65 73 2c 0a | 6f 74 68 65 72 77 69 73 |amples,.|otherwis|
|000001e0| 65 20 74 68 65 20 73 61 | 6d 70 6c 65 20 73 69 7a |e the sa|mple siz|
|000001f0| 65 20 28 69 6e 20 62 79 | 74 65 73 29 20 69 73 20 |e (in by|tes) is |
|00000200| 61 6c 77 61 79 73 20 61 | 20 70 61 72 61 6d 65 74 |always a| paramet|
|00000210| 65 72 20 6f 66 20 74 68 | 65 20 6f 70 65 72 61 74 |er of th|e operat|
|00000220| 69 6f 6e 2e 0a 0a 54 68 | 65 20 6d 6f 64 75 6c 65 |ion...Th|e module|
|00000230| 20 64 65 66 69 6e 65 73 | 20 74 68 65 20 66 6f 6c | defines| the fol|
|00000240| 6c 6f 77 69 6e 67 20 76 | 61 72 69 61 62 6c 65 73 |lowing v|ariables|
|00000250| 20 61 6e 64 20 66 75 6e | 63 74 69 6f 6e 73 3a 0a | and fun|ctions:.|
|00000260| 0a 5c 72 65 6e 65 77 63 | 6f 6d 6d 61 6e 64 7b 5c |.\renewc|ommand{\|
|00000270| 69 6e 64 65 78 73 75 62 | 69 74 65 6d 7d 7b 28 69 |indexsub|item}{(i|
|00000280| 6e 20 6d 6f 64 75 6c 65 | 20 61 75 64 69 6f 6f 70 |n module| audioop|
|00000290| 29 7d 0a 5c 62 65 67 69 | 6e 7b 65 78 63 64 65 73 |)}.\begi|n{excdes|
|000002a0| 63 7d 7b 65 72 72 6f 72 | 7d 0a 54 68 69 73 20 65 |c}{error|}.This e|
|000002b0| 78 63 65 70 74 69 6f 6e | 20 69 73 20 72 61 69 73 |xception| is rais|
|000002c0| 65 64 20 6f 6e 20 61 6c | 6c 20 65 72 72 6f 72 73 |ed on al|l errors|
|000002d0| 2c 20 73 75 63 68 20 61 | 73 20 75 6e 6b 6e 6f 77 |, such a|s unknow|
|000002e0| 6e 20 6e 75 6d 62 65 72 | 20 6f 66 20 62 79 74 65 |n number| of byte|
|000002f0| 73 0a 70 65 72 20 73 61 | 6d 70 6c 65 2c 20 65 74 |s.per sa|mple, et|
|00000300| 63 2e 0a 5c 65 6e 64 7b | 65 78 63 64 65 73 63 7d |c..\end{|excdesc}|
|00000310| 0a 0a 5c 62 65 67 69 6e | 7b 66 75 6e 63 64 65 73 |..\begin|{funcdes|
|00000320| 63 7d 7b 61 64 64 7d 7b | 66 72 61 67 6d 65 6e 74 |c}{add}{|fragment|
|00000330| 31 5c 2c 20 66 72 61 67 | 6d 65 6e 74 32 5c 2c 20 |1\, frag|ment2\, |
|00000340| 77 69 64 74 68 7d 0a 52 | 65 74 75 72 6e 20 61 20 |width}.R|eturn a |
|00000350| 66 72 61 67 6d 65 6e 74 | 20 77 68 69 63 68 20 69 |fragment| which i|
|00000360| 73 20 74 68 65 20 61 64 | 64 69 74 69 6f 6e 20 6f |s the ad|dition o|
|00000370| 66 20 74 68 65 20 74 77 | 6f 20 73 61 6d 70 6c 65 |f the tw|o sample|
|00000380| 73 20 70 61 73 73 65 64 | 20 61 73 0a 70 61 72 61 |s passed| as.para|
|00000390| 6d 65 74 65 72 73 2e 20 | 20 5c 76 61 72 7b 77 69 |meters. | \var{wi|
|000003a0| 64 74 68 7d 20 69 73 20 | 74 68 65 20 73 61 6d 70 |dth} is |the samp|
|000003b0| 6c 65 20 77 69 64 74 68 | 20 69 6e 20 62 79 74 65 |le width| in byte|
|000003c0| 73 2c 20 65 69 74 68 65 | 72 0a 5c 63 6f 64 65 7b |s, eithe|r.\code{|
|000003d0| 31 7d 2c 20 5c 63 6f 64 | 65 7b 32 7d 20 6f 72 20 |1}, \cod|e{2} or |
|000003e0| 5c 63 6f 64 65 7b 34 7d | 2e 20 20 42 6f 74 68 20 |\code{4}|. Both |
|000003f0| 66 72 61 67 6d 65 6e 74 | 73 20 73 68 6f 75 6c 64 |fragment|s should|
|00000400| 20 68 61 76 65 20 74 68 | 65 20 73 61 6d 65 0a 6c | have th|e same.l|
|00000410| 65 6e 67 74 68 2e 0a 5c | 65 6e 64 7b 66 75 6e 63 |ength..\|end{func|
|00000420| 64 65 73 63 7d 0a 0a 5c | 62 65 67 69 6e 7b 66 75 |desc}..\|begin{fu|
|00000430| 6e 63 64 65 73 63 7d 7b | 61 64 70 63 6d 32 6c 69 |ncdesc}{|adpcm2li|
|00000440| 6e 7d 7b 61 64 70 63 6d | 66 72 61 67 6d 65 6e 74 |n}{adpcm|fragment|
|00000450| 5c 2c 20 77 69 64 74 68 | 5c 2c 20 73 74 61 74 65 |\, width|\, state|
|00000460| 7d 0a 44 65 63 6f 64 65 | 20 61 6e 20 49 6e 74 65 |}.Decode| an Inte|
|00000470| 6c 2f 44 56 49 20 41 44 | 50 43 4d 20 63 6f 64 65 |l/DVI AD|PCM code|
|00000480| 64 20 66 72 61 67 6d 65 | 6e 74 20 74 6f 20 61 20 |d fragme|nt to a |
|00000490| 6c 69 6e 65 61 72 20 66 | 72 61 67 6d 65 6e 74 2e |linear f|ragment.|
|000004a0| 20 20 53 65 65 0a 74 68 | 65 20 64 65 73 63 72 69 | See.th|e descri|
|000004b0| 70 74 69 6f 6e 20 6f 66 | 20 5c 63 6f 64 65 7b 6c |ption of| \code{l|
|000004c0| 69 6e 32 61 64 70 63 6d | 7d 20 66 6f 72 20 64 65 |in2adpcm|} for de|
|000004d0| 74 61 69 6c 73 20 6f 6e | 20 41 44 50 43 4d 20 63 |tails on| ADPCM c|
|000004e0| 6f 64 69 6e 67 2e 0a 52 | 65 74 75 72 6e 20 61 20 |oding..R|eturn a |
|000004f0| 74 75 70 6c 65 20 5c 63 | 6f 64 65 7b 28 5c 76 61 |tuple \c|ode{(\va|
|00000500| 72 7b 73 61 6d 70 6c 65 | 7d 2c 20 5c 76 61 72 7b |r{sample|}, \var{|
|00000510| 6e 65 77 73 74 61 74 65 | 7d 29 7d 20 77 68 65 72 |newstate|})} wher|
|00000520| 65 20 74 68 65 20 73 61 | 6d 70 6c 65 0a 68 61 73 |e the sa|mple.has|
|00000530| 20 74 68 65 20 77 69 64 | 74 68 20 73 70 65 63 69 | the wid|th speci|
|00000540| 66 69 65 64 20 69 6e 20 | 5c 76 61 72 7b 77 69 64 |fied in |\var{wid|
|00000550| 74 68 7d 2e 0a 5c 65 6e | 64 7b 66 75 6e 63 64 65 |th}..\en|d{funcde|
|00000560| 73 63 7d 0a 0a 5c 62 65 | 67 69 6e 7b 66 75 6e 63 |sc}..\be|gin{func|
|00000570| 64 65 73 63 7d 7b 61 64 | 70 63 6d 33 32 6c 69 6e |desc}{ad|pcm32lin|
|00000580| 7d 7b 61 64 70 63 6d 66 | 72 61 67 6d 65 6e 74 5c |}{adpcmf|ragment\|
|00000590| 2c 20 77 69 64 74 68 5c | 2c 20 73 74 61 74 65 7d |, width\|, state}|
|000005a0| 0a 44 65 63 6f 64 65 20 | 61 6e 20 61 6c 74 65 72 |.Decode |an alter|
|000005b0| 6e 61 74 69 76 65 20 33 | 2d 62 69 74 20 41 44 50 |native 3|-bit ADP|
|000005c0| 43 4d 20 63 6f 64 65 2e | 20 20 53 65 65 20 5c 63 |CM code.| See \c|
|000005d0| 6f 64 65 7b 6c 69 6e 32 | 61 64 70 63 6d 33 7d 20 |ode{lin2|adpcm3} |
|000005e0| 66 6f 72 0a 64 65 74 61 | 69 6c 73 2e 0a 5c 65 6e |for.deta|ils..\en|
|000005f0| 64 7b 66 75 6e 63 64 65 | 73 63 7d 0a 0a 5c 62 65 |d{funcde|sc}..\be|
|00000600| 67 69 6e 7b 66 75 6e 63 | 64 65 73 63 7d 7b 61 76 |gin{func|desc}{av|
|00000610| 67 7d 7b 66 72 61 67 6d | 65 6e 74 5c 2c 20 77 69 |g}{fragm|ent\, wi|
|00000620| 64 74 68 7d 0a 52 65 74 | 75 72 6e 20 74 68 65 20 |dth}.Ret|urn the |
|00000630| 61 76 65 72 61 67 65 20 | 6f 76 65 72 20 61 6c 6c |average |over all|
|00000640| 20 73 61 6d 70 6c 65 73 | 20 69 6e 20 74 68 65 20 | samples| in the |
|00000650| 66 72 61 67 6d 65 6e 74 | 2e 0a 5c 65 6e 64 7b 66 |fragment|..\end{f|
|00000660| 75 6e 63 64 65 73 63 7d | 0a 0a 5c 62 65 67 69 6e |uncdesc}|..\begin|
|00000670| 7b 66 75 6e 63 64 65 73 | 63 7d 7b 61 76 67 70 70 |{funcdes|c}{avgpp|
|00000680| 7d 7b 66 72 61 67 6d 65 | 6e 74 5c 2c 20 77 69 64 |}{fragme|nt\, wid|
|00000690| 74 68 7d 0a 52 65 74 75 | 72 6e 20 74 68 65 20 61 |th}.Retu|rn the a|
|000006a0| 76 65 72 61 67 65 20 70 | 65 61 6b 2d 70 65 61 6b |verage p|eak-peak|
|000006b0| 20 76 61 6c 75 65 20 6f | 76 65 72 20 61 6c 6c 20 | value o|ver all |
|000006c0| 73 61 6d 70 6c 65 73 20 | 69 6e 20 74 68 65 20 66 |samples |in the f|
|000006d0| 72 61 67 6d 65 6e 74 2e | 0a 4e 6f 20 66 69 6c 74 |ragment.|.No filt|
|000006e0| 65 72 69 6e 67 20 69 73 | 20 64 6f 6e 65 2c 20 73 |ering is| done, s|
|000006f0| 6f 20 74 68 65 20 75 73 | 65 66 75 6c 6e 65 73 73 |o the us|efulness|
|00000700| 20 6f 66 20 74 68 69 73 | 20 72 6f 75 74 69 6e 65 | of this| routine|
|00000710| 20 69 73 0a 71 75 65 73 | 74 69 6f 6e 61 62 6c 65 | is.ques|tionable|
|00000720| 2e 0a 5c 65 6e 64 7b 66 | 75 6e 63 64 65 73 63 7d |..\end{f|uncdesc}|
|00000730| 0a 0a 5c 62 65 67 69 6e | 7b 66 75 6e 63 64 65 73 |..\begin|{funcdes|
|00000740| 63 7d 7b 62 69 61 73 7d | 7b 66 72 61 67 6d 65 6e |c}{bias}|{fragmen|
|00000750| 74 5c 2c 20 77 69 64 74 | 68 5c 2c 20 62 69 61 73 |t\, widt|h\, bias|
|00000760| 7d 0a 52 65 74 75 72 6e | 20 61 20 66 72 61 67 6d |}.Return| a fragm|
|00000770| 65 6e 74 20 74 68 61 74 | 20 69 73 20 74 68 65 20 |ent that| is the |
|00000780| 6f 72 69 67 69 6e 61 6c | 20 66 72 61 67 6d 65 6e |original| fragmen|
|00000790| 74 20 77 69 74 68 20 61 | 20 62 69 61 73 20 61 64 |t with a| bias ad|
|000007a0| 64 65 64 20 74 6f 0a 65 | 61 63 68 20 73 61 6d 70 |ded to.e|ach samp|
|000007b0| 6c 65 2e 0a 5c 65 6e 64 | 7b 66 75 6e 63 64 65 73 |le..\end|{funcdes|
|000007c0| 63 7d 0a 0a 5c 62 65 67 | 69 6e 7b 66 75 6e 63 64 |c}..\beg|in{funcd|
|000007d0| 65 73 63 7d 7b 63 72 6f | 73 73 7d 7b 66 72 61 67 |esc}{cro|ss}{frag|
|000007e0| 6d 65 6e 74 5c 2c 20 77 | 69 64 74 68 7d 0a 52 65 |ment\, w|idth}.Re|
|000007f0| 74 75 72 6e 20 74 68 65 | 20 6e 75 6d 62 65 72 20 |turn the| number |
|00000800| 6f 66 20 7a 65 72 6f 20 | 63 72 6f 73 73 69 6e 67 |of zero |crossing|
|00000810| 73 20 69 6e 20 74 68 65 | 20 66 72 61 67 6d 65 6e |s in the| fragmen|
|00000820| 74 20 70 61 73 73 65 64 | 20 61 73 20 61 6e 0a 61 |t passed| as an.a|
|00000830| 72 67 75 6d 65 6e 74 2e | 0a 5c 65 6e 64 7b 66 75 |rgument.|.\end{fu|
|00000840| 6e 63 64 65 73 63 7d 0a | 0a 5c 62 65 67 69 6e 7b |ncdesc}.|.\begin{|
|00000850| 66 75 6e 63 64 65 73 63 | 7d 7b 66 69 6e 64 66 61 |funcdesc|}{findfa|
|00000860| 63 74 6f 72 7d 7b 66 72 | 61 67 6d 65 6e 74 5c 2c |ctor}{fr|agment\,|
|00000870| 20 72 65 66 65 72 65 6e | 63 65 7d 0a 52 65 74 75 | referen|ce}.Retu|
|00000880| 72 6e 20 61 20 66 61 63 | 74 6f 72 20 5c 76 61 72 |rn a fac|tor \var|
|00000890| 7b 46 7d 20 73 75 63 68 | 20 74 68 61 74 0a 5c 63 |{F} such| that.\c|
|000008a0| 6f 64 65 7b 72 6d 73 28 | 61 64 64 28 66 72 61 67 |ode{rms(|add(frag|
|000008b0| 6d 65 6e 74 2c 20 6d 75 | 6c 28 72 65 66 65 72 65 |ment, mu|l(refere|
|000008c0| 6e 63 65 2c 20 2d 46 29 | 29 29 7d 20 69 73 20 6d |nce, -F)|))} is m|
|000008d0| 69 6e 69 6d 61 6c 2c 20 | 69 2e 65 2e 2c 0a 72 65 |inimal, |i.e.,.re|
|000008e0| 74 75 72 6e 20 74 68 65 | 20 66 61 63 74 6f 72 20 |turn the| factor |
|000008f0| 77 69 74 68 20 77 68 69 | 63 68 20 79 6f 75 20 73 |with whi|ch you s|
|00000900| 68 6f 75 6c 64 20 6d 75 | 6c 74 69 70 6c 79 20 5c |hould mu|ltiply \|
|00000910| 76 61 72 7b 72 65 66 65 | 72 65 6e 63 65 7d 20 74 |var{refe|rence} t|
|00000920| 6f 0a 6d 61 6b 65 20 69 | 74 20 6d 61 74 63 68 20 |o.make i|t match |
|00000930| 61 73 20 77 65 6c 6c 20 | 61 73 20 70 6f 73 73 69 |as well |as possi|
|00000940| 62 6c 65 20 74 6f 20 5c | 76 61 72 7b 66 72 61 67 |ble to \|var{frag|
|00000950| 6d 65 6e 74 7d 2e 20 20 | 54 68 65 20 66 72 61 67 |ment}. |The frag|
|00000960| 6d 65 6e 74 73 0a 73 68 | 6f 75 6c 64 20 62 6f 74 |ments.sh|ould bot|
|00000970| 68 20 63 6f 6e 74 61 69 | 6e 20 32 2d 62 79 74 65 |h contai|n 2-byte|
|00000980| 20 73 61 6d 70 6c 65 73 | 2e 0a 0a 54 68 65 20 74 | samples|...The t|
|00000990| 69 6d 65 20 74 61 6b 65 | 6e 20 62 79 20 74 68 69 |ime take|n by thi|
|000009a0| 73 20 72 6f 75 74 69 6e | 65 20 69 73 20 70 72 6f |s routin|e is pro|
|000009b0| 70 6f 72 74 69 6f 6e 61 | 6c 20 74 6f 20 5c 63 6f |portiona|l to \co|
|000009c0| 64 65 7b 6c 65 6e 28 66 | 72 61 67 6d 65 6e 74 29 |de{len(f|ragment)|
|000009d0| 7d 2e 20 0a 5c 65 6e 64 | 7b 66 75 6e 63 64 65 73 |}. .\end|{funcdes|
|000009e0| 63 7d 0a 0a 5c 62 65 67 | 69 6e 7b 66 75 6e 63 64 |c}..\beg|in{funcd|
|000009f0| 65 73 63 7d 7b 66 69 6e | 64 66 69 74 7d 7b 66 72 |esc}{fin|dfit}{fr|
|00000a00| 61 67 6d 65 6e 74 5c 2c | 20 72 65 66 65 72 65 6e |agment\,| referen|
|00000a10| 63 65 7d 0a 54 68 69 73 | 20 72 6f 75 74 69 6e 65 |ce}.This| routine|
|00000a20| 20 28 77 68 69 63 68 20 | 6f 6e 6c 79 20 61 63 63 | (which |only acc|
|00000a30| 65 70 74 73 20 32 2d 62 | 79 74 65 20 73 61 6d 70 |epts 2-b|yte samp|
|00000a40| 6c 65 20 66 72 61 67 6d | 65 6e 74 73 29 0a 0a 54 |le fragm|ents)..T|
|00000a50| 72 79 20 74 6f 20 6d 61 | 74 63 68 20 5c 76 61 72 |ry to ma|tch \var|
|00000a60| 7b 72 65 66 65 72 65 6e | 63 65 7d 20 61 73 20 77 |{referen|ce} as w|
|00000a70| 65 6c 6c 20 61 73 20 70 | 6f 73 73 69 62 6c 65 20 |ell as p|ossible |
|00000a80| 74 6f 20 61 20 70 6f 72 | 74 69 6f 6e 20 6f 66 0a |to a por|tion of.|
|00000a90| 5c 76 61 72 7b 66 72 61 | 67 6d 65 6e 74 7d 20 28 |\var{fra|gment} (|
|00000aa0| 77 68 69 63 68 20 73 68 | 6f 75 6c 64 20 62 65 20 |which sh|ould be |
|00000ab0| 74 68 65 20 6c 6f 6e 67 | 65 72 20 66 72 61 67 6d |the long|er fragm|
|00000ac0| 65 6e 74 29 2e 20 20 54 | 68 69 73 20 69 73 0a 28 |ent). T|his is.(|
|00000ad0| 63 6f 6e 63 65 70 74 75 | 61 6c 6c 79 29 20 64 6f |conceptu|ally) do|
|00000ae0| 6e 65 20 62 79 20 74 61 | 6b 69 6e 67 20 73 6c 69 |ne by ta|king sli|
|00000af0| 63 65 73 20 6f 75 74 20 | 6f 66 20 5c 76 61 72 7b |ces out |of \var{|
|00000b00| 66 72 61 67 6d 65 6e 74 | 7d 2c 20 75 73 69 6e 67 |fragment|}, using|
|00000b10| 0a 5c 63 6f 64 65 7b 66 | 69 6e 64 66 61 63 74 6f |.\code{f|indfacto|
|00000b20| 72 7d 20 74 6f 20 63 6f | 6d 70 75 74 65 20 74 68 |r} to co|mpute th|
|00000b30| 65 20 62 65 73 74 20 6d | 61 74 63 68 2c 20 61 6e |e best m|atch, an|
|00000b40| 64 20 6d 69 6e 69 6d 69 | 7a 69 6e 67 20 74 68 65 |d minimi|zing the|
|00000b50| 0a 72 65 73 75 6c 74 2e | 20 20 54 68 65 20 66 72 |.result.| The fr|
|00000b60| 61 67 6d 65 6e 74 73 20 | 73 68 6f 75 6c 64 20 62 |agments |should b|
|00000b70| 6f 74 68 20 63 6f 6e 74 | 61 69 6e 20 32 2d 62 79 |oth cont|ain 2-by|
|00000b80| 74 65 20 73 61 6d 70 6c | 65 73 2e 20 20 52 65 74 |te sampl|es. Ret|
|00000b90| 75 72 6e 20 61 0a 74 75 | 70 6c 65 20 5c 63 6f 64 |urn a.tu|ple \cod|
|00000ba0| 65 7b 28 5c 76 61 72 7b | 6f 66 66 73 65 74 7d 2c |e{(\var{|offset},|
|00000bb0| 20 5c 76 61 72 7b 66 61 | 63 74 6f 72 7d 29 7d 20 | \var{fa|ctor})} |
|00000bc0| 77 68 65 72 65 20 5c 76 | 61 72 7b 6f 66 66 73 65 |where \v|ar{offse|
|00000bd0| 74 7d 20 69 73 20 74 68 | 65 0a 28 69 6e 74 65 67 |t} is th|e.(integ|
|00000be0| 65 72 29 20 6f 66 66 73 | 65 74 20 69 6e 74 6f 20 |er) offs|et into |
|00000bf0| 5c 76 61 72 7b 66 72 61 | 67 6d 65 6e 74 7d 20 77 |\var{fra|gment} w|
|00000c00| 68 65 72 65 20 74 68 65 | 20 6f 70 74 69 6d 61 6c |here the| optimal|
|00000c10| 20 6d 61 74 63 68 20 73 | 74 61 72 74 65 64 0a 61 | match s|tarted.a|
|00000c20| 6e 64 20 5c 76 61 72 7b | 66 61 63 74 6f 72 7d 20 |nd \var{|factor} |
|00000c30| 69 73 20 74 68 65 20 28 | 66 6c 6f 61 74 69 6e 67 |is the (|floating|
|00000c40| 2d 70 6f 69 6e 74 29 20 | 66 61 63 74 6f 72 20 61 |-point) |factor a|
|00000c50| 73 20 70 65 72 0a 5c 63 | 6f 64 65 7b 66 69 6e 64 |s per.\c|ode{find|
|00000c60| 66 61 63 74 6f 72 7d 2e | 0a 5c 65 6e 64 7b 66 75 |factor}.|.\end{fu|
|00000c70| 6e 63 64 65 73 63 7d 0a | 0a 5c 62 65 67 69 6e 7b |ncdesc}.|.\begin{|
|00000c80| 66 75 6e 63 64 65 73 63 | 7d 7b 66 69 6e 64 6d 61 |funcdesc|}{findma|
|00000c90| 78 7d 7b 66 72 61 67 6d | 65 6e 74 5c 2c 20 6c 65 |x}{fragm|ent\, le|
|00000ca0| 6e 67 74 68 7d 0a 53 65 | 61 72 63 68 20 5c 76 61 |ngth}.Se|arch \va|
|00000cb0| 72 7b 66 72 61 67 6d 65 | 6e 74 7d 20 66 6f 72 20 |r{fragme|nt} for |
|00000cc0| 61 20 73 6c 69 63 65 20 | 6f 66 20 6c 65 6e 67 74 |a slice |of lengt|
|00000cd0| 68 20 5c 76 61 72 7b 6c | 65 6e 67 74 68 7d 20 73 |h \var{l|ength} s|
|00000ce0| 61 6d 70 6c 65 73 20 28 | 6e 6f 74 0a 62 79 74 65 |amples (|not.byte|
|00000cf0| 73 21 29 5c 20 77 69 74 | 68 20 6d 61 78 69 6d 75 |s!)\ wit|h maximu|
|00000d00| 6d 20 65 6e 65 72 67 79 | 2c 20 69 2e 65 2e 2c 20 |m energy|, i.e., |
|00000d10| 72 65 74 75 72 6e 20 5c | 76 61 72 7b 69 7d 20 66 |return \|var{i} f|
|00000d20| 6f 72 20 77 68 69 63 68 | 0a 5c 63 6f 64 65 7b 72 |or which|.\code{r|
|00000d30| 6d 73 28 66 72 61 67 6d | 65 6e 74 5b 69 2a 32 3a |ms(fragm|ent[i*2:|
|00000d40| 28 69 2b 6c 65 6e 67 74 | 68 29 2a 32 5d 29 7d 20 |(i+lengt|h)*2])} |
|00000d50| 69 73 20 6d 61 78 69 6d | 61 6c 2e 20 20 54 68 65 |is maxim|al. The|
|00000d60| 20 66 72 61 67 6d 65 6e | 74 73 0a 73 68 6f 75 6c | fragmen|ts.shoul|
|00000d70| 64 20 62 6f 74 68 20 63 | 6f 6e 74 61 69 6e 20 32 |d both c|ontain 2|
|00000d80| 2d 62 79 74 65 20 73 61 | 6d 70 6c 65 73 2e 0a 0a |-byte sa|mples...|
|00000d90| 54 68 65 20 72 6f 75 74 | 69 6e 65 20 74 61 6b 65 |The rout|ine take|
|00000da0| 73 20 74 69 6d 65 20 70 | 72 6f 70 6f 72 74 69 6f |s time p|roportio|
|00000db0| 6e 61 6c 20 74 6f 20 5c | 63 6f 64 65 7b 6c 65 6e |nal to \|code{len|
|00000dc0| 28 66 72 61 67 6d 65 6e | 74 29 7d 2e 0a 5c 65 6e |(fragmen|t)}..\en|
|00000dd0| 64 7b 66 75 6e 63 64 65 | 73 63 7d 0a 0a 5c 62 65 |d{funcde|sc}..\be|
|00000de0| 67 69 6e 7b 66 75 6e 63 | 64 65 73 63 7d 7b 67 65 |gin{func|desc}{ge|
|00000df0| 74 73 61 6d 70 6c 65 7d | 7b 66 72 61 67 6d 65 6e |tsample}|{fragmen|
|00000e00| 74 5c 2c 20 77 69 64 74 | 68 5c 2c 20 69 6e 64 65 |t\, widt|h\, inde|
|00000e10| 78 7d 0a 52 65 74 75 72 | 6e 20 74 68 65 20 76 61 |x}.Retur|n the va|
|00000e20| 6c 75 65 20 6f 66 20 73 | 61 6d 70 6c 65 20 5c 76 |lue of s|ample \v|
|00000e30| 61 72 7b 69 6e 64 65 78 | 7d 20 66 72 6f 6d 20 74 |ar{index|} from t|
|00000e40| 68 65 20 66 72 61 67 6d | 65 6e 74 2e 0a 5c 65 6e |he fragm|ent..\en|
|00000e50| 64 7b 66 75 6e 63 64 65 | 73 63 7d 0a 0a 5c 62 65 |d{funcde|sc}..\be|
|00000e60| 67 69 6e 7b 66 75 6e 63 | 64 65 73 63 7d 7b 6c 69 |gin{func|desc}{li|
|00000e70| 6e 32 6c 69 6e 7d 7b 66 | 72 61 67 6d 65 6e 74 5c |n2lin}{f|ragment\|
|00000e80| 2c 20 77 69 64 74 68 5c | 2c 20 6e 65 77 77 69 64 |, width\|, newwid|
|00000e90| 74 68 7d 0a 43 6f 6e 76 | 65 72 74 20 73 61 6d 70 |th}.Conv|ert samp|
|00000ea0| 6c 65 73 20 62 65 74 77 | 65 65 6e 20 31 2d 2c 20 |les betw|een 1-, |
|00000eb0| 32 2d 20 61 6e 64 20 34 | 2d 62 79 74 65 20 66 6f |2- and 4|-byte fo|
|00000ec0| 72 6d 61 74 73 2e 0a 5c | 65 6e 64 7b 66 75 6e 63 |rmats..\|end{func|
|00000ed0| 64 65 73 63 7d 0a 0a 5c | 62 65 67 69 6e 7b 66 75 |desc}..\|begin{fu|
|00000ee0| 6e 63 64 65 73 63 7d 7b | 6c 69 6e 32 61 64 70 63 |ncdesc}{|lin2adpc|
|00000ef0| 6d 7d 7b 66 72 61 67 6d | 65 6e 74 5c 2c 20 77 69 |m}{fragm|ent\, wi|
|00000f00| 64 74 68 5c 2c 20 73 74 | 61 74 65 7d 0a 43 6f 6e |dth\, st|ate}.Con|
|00000f10| 76 65 72 74 20 73 61 6d | 70 6c 65 73 20 74 6f 20 |vert sam|ples to |
|00000f20| 34 20 62 69 74 20 49 6e | 74 65 6c 2f 44 56 49 20 |4 bit In|tel/DVI |
|00000f30| 41 44 50 43 4d 20 65 6e | 63 6f 64 69 6e 67 2e 20 |ADPCM en|coding. |
|00000f40| 20 41 44 50 43 4d 20 63 | 6f 64 69 6e 67 20 69 73 | ADPCM c|oding is|
|00000f50| 20 61 6e 0a 61 64 61 70 | 74 69 76 65 20 63 6f 64 | an.adap|tive cod|
|00000f60| 69 6e 67 20 73 63 68 65 | 6d 65 2c 20 77 68 65 72 |ing sche|me, wher|
|00000f70| 65 62 79 20 65 61 63 68 | 20 34 20 62 69 74 20 6e |eby each| 4 bit n|
|00000f80| 75 6d 62 65 72 20 69 73 | 20 74 68 65 20 64 69 66 |umber is| the dif|
|00000f90| 66 65 72 65 6e 63 65 0a | 62 65 74 77 65 65 6e 20 |ference.|between |
|00000fa0| 6f 6e 65 20 73 61 6d 70 | 6c 65 20 61 6e 64 20 74 |one samp|le and t|
|00000fb0| 68 65 20 6e 65 78 74 2c | 20 64 69 76 69 64 65 64 |he next,| divided|
|00000fc0| 20 62 79 20 61 20 28 76 | 61 72 79 69 6e 67 29 20 | by a (v|arying) |
|00000fd0| 73 74 65 70 2e 20 20 54 | 68 65 0a 49 6e 74 65 6c |step. T|he.Intel|
|00000fe0| 2f 44 56 49 20 41 44 50 | 43 4d 20 61 6c 67 6f 72 |/DVI ADP|CM algor|
|00000ff0| 69 74 68 6d 20 68 61 73 | 20 62 65 65 6e 20 73 65 |ithm has| been se|
|00001000| 6c 65 63 74 65 64 20 66 | 6f 72 20 75 73 65 20 62 |lected f|or use b|
|00001010| 79 20 74 68 65 20 49 4d | 41 2c 20 73 6f 20 69 74 |y the IM|A, so it|
|00001020| 0a 6d 61 79 20 77 65 6c | 6c 20 62 65 63 6f 6d 65 |.may wel|l become|
|00001030| 20 61 20 73 74 61 6e 64 | 61 72 64 2e 0a 0a 5c 63 | a stand|ard...\c|
|00001040| 6f 64 65 7b 53 74 61 74 | 65 7d 20 69 73 20 61 20 |ode{Stat|e} is a |
|00001050| 74 75 70 6c 65 20 63 6f | 6e 74 61 69 6e 69 6e 67 |tuple co|ntaining|
|00001060| 20 74 68 65 20 73 74 61 | 74 65 20 6f 66 20 74 68 | the sta|te of th|
|00001070| 65 20 63 6f 64 65 72 2e | 20 20 54 68 65 20 63 6f |e coder.| The co|
|00001080| 64 65 72 0a 72 65 74 75 | 72 6e 73 20 61 20 74 75 |der.retu|rns a tu|
|00001090| 70 6c 65 20 5c 63 6f 64 | 65 7b 28 5c 76 61 72 7b |ple \cod|e{(\var{|
|000010a0| 61 64 70 63 6d 66 72 61 | 67 7d 2c 20 5c 76 61 72 |adpcmfra|g}, \var|
|000010b0| 7b 6e 65 77 73 74 61 74 | 65 7d 29 7d 2c 20 61 6e |{newstat|e})}, an|
|000010c0| 64 20 74 68 65 0a 5c 76 | 61 72 7b 6e 65 77 73 74 |d the.\v|ar{newst|
|000010d0| 61 74 65 7d 20 73 68 6f | 75 6c 64 20 62 65 20 70 |ate} sho|uld be p|
|000010e0| 61 73 73 65 64 20 74 6f | 20 74 68 65 20 6e 65 78 |assed to| the nex|
|000010f0| 74 20 63 61 6c 6c 20 6f | 66 20 6c 69 6e 32 61 64 |t call o|f lin2ad|
|00001100| 70 63 6d 2e 20 20 49 6e | 20 74 68 65 0a 69 6e 69 |pcm. In| the.ini|
|00001110| 74 69 61 6c 20 63 61 6c | 6c 20 5c 63 6f 64 65 7b |tial cal|l \code{|
|00001120| 4e 6f 6e 65 7d 20 63 61 | 6e 20 62 65 20 70 61 73 |None} ca|n be pas|
|00001130| 73 65 64 20 61 73 20 74 | 68 65 20 73 74 61 74 65 |sed as t|he state|
|00001140| 2e 20 20 5c 76 61 72 7b | 61 64 70 63 6d 66 72 61 |. \var{|adpcmfra|
|00001150| 67 7d 0a 69 73 20 74 68 | 65 20 41 44 50 43 4d 20 |g}.is th|e ADPCM |
|00001160| 63 6f 64 65 64 20 66 72 | 61 67 6d 65 6e 74 20 70 |coded fr|agment p|
|00001170| 61 63 6b 65 64 20 32 20 | 34 2d 62 69 74 20 76 61 |acked 2 |4-bit va|
|00001180| 6c 75 65 73 20 70 65 72 | 20 62 79 74 65 2e 0a 5c |lues per| byte..\|
|00001190| 65 6e 64 7b 66 75 6e 63 | 64 65 73 63 7d 0a 0a 5c |end{func|desc}..\|
|000011a0| 62 65 67 69 6e 7b 66 75 | 6e 63 64 65 73 63 7d 7b |begin{fu|ncdesc}{|
|000011b0| 6c 69 6e 32 61 64 70 63 | 6d 33 7d 7b 66 72 61 67 |lin2adpc|m3}{frag|
|000011c0| 6d 65 6e 74 5c 2c 20 77 | 69 64 74 68 5c 2c 20 73 |ment\, w|idth\, s|
|000011d0| 74 61 74 65 7d 0a 54 68 | 69 73 20 69 73 20 61 6e |tate}.Th|is is an|
|000011e0| 20 61 6c 74 65 72 6e 61 | 74 69 76 65 20 41 44 50 | alterna|tive ADP|
|000011f0| 43 4d 20 63 6f 64 65 72 | 20 74 68 61 74 20 75 73 |CM coder| that us|
|00001200| 65 73 20 6f 6e 6c 79 20 | 33 20 62 69 74 73 20 70 |es only |3 bits p|
|00001210| 65 72 20 73 61 6d 70 6c | 65 2e 0a 49 74 20 69 73 |er sampl|e..It is|
|00001220| 20 6e 6f 74 20 63 6f 6d | 70 61 74 69 62 6c 65 20 | not com|patible |
|00001230| 77 69 74 68 20 74 68 65 | 20 49 6e 74 65 6c 2f 44 |with the| Intel/D|
|00001240| 56 49 20 41 44 50 43 4d | 20 63 6f 64 65 72 20 61 |VI ADPCM| coder a|
|00001250| 6e 64 20 69 74 73 20 6f | 75 74 70 75 74 20 69 73 |nd its o|utput is|
|00001260| 0a 6e 6f 74 20 70 61 63 | 6b 65 64 20 28 64 75 65 |.not pac|ked (due|
|00001270| 20 74 6f 20 6c 61 7a 69 | 6e 65 73 73 20 6f 6e 20 | to lazi|ness on |
|00001280| 74 68 65 20 73 69 64 65 | 20 6f 66 20 74 68 65 20 |the side| of the |
|00001290| 61 75 74 68 6f 72 29 2e | 20 20 49 74 73 20 75 73 |author).| Its us|
|000012a0| 65 20 69 73 0a 64 69 73 | 63 6f 75 72 61 67 65 64 |e is.dis|couraged|
|000012b0| 2e 0a 5c 65 6e 64 7b 66 | 75 6e 63 64 65 73 63 7d |..\end{f|uncdesc}|
|000012c0| 0a 0a 5c 62 65 67 69 6e | 7b 66 75 6e 63 64 65 73 |..\begin|{funcdes|
|000012d0| 63 7d 7b 6c 69 6e 32 75 | 6c 61 77 7d 7b 66 72 61 |c}{lin2u|law}{fra|
|000012e0| 67 6d 65 6e 74 5c 2c 20 | 77 69 64 74 68 7d 0a 43 |gment\, |width}.C|
|000012f0| 6f 6e 76 65 72 74 20 73 | 61 6d 70 6c 65 73 20 69 |onvert s|amples i|
|00001300| 6e 20 74 68 65 20 61 75 | 64 69 6f 20 66 72 61 67 |n the au|dio frag|
|00001310| 6d 65 6e 74 20 74 6f 20 | 55 2d 4c 41 57 20 65 6e |ment to |U-LAW en|
|00001320| 63 6f 64 69 6e 67 20 61 | 6e 64 20 72 65 74 75 72 |coding a|nd retur|
|00001330| 6e 0a 74 68 69 73 20 61 | 73 20 61 20 50 79 74 68 |n.this a|s a Pyth|
|00001340| 6f 6e 20 73 74 72 69 6e | 67 2e 20 20 55 2d 4c 41 |on strin|g. U-LA|
|00001350| 57 20 69 73 20 61 6e 20 | 61 75 64 69 6f 20 65 6e |W is an |audio en|
|00001360| 63 6f 64 69 6e 67 20 66 | 6f 72 6d 61 74 20 77 68 |coding f|ormat wh|
|00001370| 65 72 65 62 79 0a 79 6f | 75 20 67 65 74 20 61 20 |ereby.yo|u get a |
|00001380| 64 79 6e 61 6d 69 63 20 | 72 61 6e 67 65 20 6f 66 |dynamic |range of|
|00001390| 20 61 62 6f 75 74 20 31 | 34 20 62 69 74 73 20 75 | about 1|4 bits u|
|000013a0| 73 69 6e 67 20 6f 6e 6c | 79 20 38 20 62 69 74 20 |sing onl|y 8 bit |
|000013b0| 73 61 6d 70 6c 65 73 2e | 20 20 49 74 0a 69 73 20 |samples.| It.is |
|000013c0| 75 73 65 64 20 62 79 20 | 74 68 65 20 53 75 6e 20 |used by |the Sun |
|000013d0| 61 75 64 69 6f 20 68 61 | 72 64 77 61 72 65 2c 20 |audio ha|rdware, |
|000013e0| 61 6d 6f 6e 67 20 6f 74 | 68 65 72 73 2e 0a 5c 65 |among ot|hers..\e|
|000013f0| 6e 64 7b 66 75 6e 63 64 | 65 73 63 7d 0a 0a 5c 62 |nd{funcd|esc}..\b|
|00001400| 65 67 69 6e 7b 66 75 6e | 63 64 65 73 63 7d 7b 6d |egin{fun|cdesc}{m|
|00001410| 69 6e 6d 61 78 7d 7b 66 | 72 61 67 6d 65 6e 74 5c |inmax}{f|ragment\|
|00001420| 2c 20 77 69 64 74 68 7d | 0a 52 65 74 75 72 6e 20 |, width}|.Return |
|00001430| 61 20 74 75 70 6c 65 20 | 63 6f 6e 73 69 73 74 69 |a tuple |consisti|
|00001440| 6e 67 20 6f 66 20 74 68 | 65 20 6d 69 6e 69 6d 75 |ng of th|e minimu|
|00001450| 6d 20 61 6e 64 20 6d 61 | 78 69 6d 75 6d 20 76 61 |m and ma|ximum va|
|00001460| 6c 75 65 73 20 6f 66 20 | 61 6c 6c 0a 73 61 6d 70 |lues of |all.samp|
|00001470| 6c 65 73 20 69 6e 20 74 | 68 65 20 73 6f 75 6e 64 |les in t|he sound|
|00001480| 20 66 72 61 67 6d 65 6e | 74 2e 0a 5c 65 6e 64 7b | fragmen|t..\end{|
|00001490| 66 75 6e 63 64 65 73 63 | 7d 0a 0a 5c 62 65 67 69 |funcdesc|}..\begi|
|000014a0| 6e 7b 66 75 6e 63 64 65 | 73 63 7d 7b 6d 61 78 7d |n{funcde|sc}{max}|
|000014b0| 7b 66 72 61 67 6d 65 6e | 74 5c 2c 20 77 69 64 74 |{fragmen|t\, widt|
|000014c0| 68 7d 0a 52 65 74 75 72 | 6e 20 74 68 65 20 6d 61 |h}.Retur|n the ma|
|000014d0| 78 69 6d 75 6d 20 6f 66 | 20 74 68 65 20 7b 5c 65 |ximum of| the {\e|
|000014e0| 6d 20 61 62 73 6f 6c 75 | 74 65 20 76 61 6c 75 65 |m absolu|te value|
|000014f0| 7d 20 6f 66 20 61 6c 6c | 20 73 61 6d 70 6c 65 73 |} of all| samples|
|00001500| 20 69 6e 20 61 0a 66 72 | 61 67 6d 65 6e 74 2e 0a | in a.fr|agment..|
|00001510| 5c 65 6e 64 7b 66 75 6e | 63 64 65 73 63 7d 0a 0a |\end{fun|cdesc}..|
|00001520| 5c 62 65 67 69 6e 7b 66 | 75 6e 63 64 65 73 63 7d |\begin{f|uncdesc}|
|00001530| 7b 6d 61 78 70 70 7d 7b | 66 72 61 67 6d 65 6e 74 |{maxpp}{|fragment|
|00001540| 5c 2c 20 77 69 64 74 68 | 7d 0a 52 65 74 75 72 6e |\, width|}.Return|
|00001550| 20 74 68 65 20 6d 61 78 | 69 6d 75 6d 20 70 65 61 | the max|imum pea|
|00001560| 6b 2d 70 65 61 6b 20 76 | 61 6c 75 65 20 69 6e 20 |k-peak v|alue in |
|00001570| 74 68 65 20 73 6f 75 6e | 64 20 66 72 61 67 6d 65 |the soun|d fragme|
|00001580| 6e 74 2e 0a 5c 65 6e 64 | 7b 66 75 6e 63 64 65 73 |nt..\end|{funcdes|
|00001590| 63 7d 0a 0a 5c 62 65 67 | 69 6e 7b 66 75 6e 63 64 |c}..\beg|in{funcd|
|000015a0| 65 73 63 7d 7b 6d 75 6c | 7d 7b 66 72 61 67 6d 65 |esc}{mul|}{fragme|
|000015b0| 6e 74 5c 2c 20 77 69 64 | 74 68 5c 2c 20 66 61 63 |nt\, wid|th\, fac|
|000015c0| 74 6f 72 7d 0a 52 65 74 | 75 72 6e 20 61 20 66 72 |tor}.Ret|urn a fr|
|000015d0| 61 67 6d 65 6e 74 20 74 | 68 61 74 20 68 61 73 20 |agment t|hat has |
|000015e0| 61 6c 6c 20 73 61 6d 70 | 6c 65 73 20 69 6e 20 74 |all samp|les in t|
|000015f0| 68 65 20 6f 72 69 67 69 | 6e 61 6c 20 66 72 61 6d |he origi|nal fram|
|00001600| 67 65 6e 74 0a 6d 75 6c | 74 69 70 6c 69 65 64 20 |gent.mul|tiplied |
|00001610| 62 79 20 74 68 65 20 66 | 6c 6f 61 74 69 6e 67 2d |by the f|loating-|
|00001620| 70 6f 69 6e 74 20 76 61 | 6c 75 65 20 5c 76 61 72 |point va|lue \var|
|00001630| 7b 66 61 63 74 6f 72 7d | 2e 20 20 4f 76 65 72 66 |{factor}|. Overf|
|00001640| 6c 6f 77 20 69 73 0a 73 | 69 6c 65 6e 74 6c 79 20 |low is.s|ilently |
|00001650| 69 67 6e 6f 72 65 64 2e | 0a 5c 65 6e 64 7b 66 75 |ignored.|.\end{fu|
|00001660| 6e 63 64 65 73 63 7d 0a | 0a 5c 62 65 67 69 6e 7b |ncdesc}.|.\begin{|
|00001670| 66 75 6e 63 64 65 73 63 | 7d 7b 72 65 76 65 72 73 |funcdesc|}{revers|
|00001680| 65 7d 7b 66 72 61 67 6d | 65 6e 74 5c 2c 20 77 69 |e}{fragm|ent\, wi|
|00001690| 64 74 68 7d 0a 52 65 76 | 65 72 73 65 20 74 68 65 |dth}.Rev|erse the|
|000016a0| 20 73 61 6d 70 6c 65 73 | 20 69 6e 20 61 20 66 72 | samples| in a fr|
|000016b0| 61 67 6d 65 6e 74 20 61 | 6e 64 20 72 65 74 75 72 |agment a|nd retur|
|000016c0| 6e 73 20 74 68 65 20 6d | 6f 64 69 66 69 65 64 20 |ns the m|odified |
|000016d0| 66 72 61 67 6d 65 6e 74 | 2e 0a 5c 65 6e 64 7b 66 |fragment|..\end{f|
|000016e0| 75 6e 63 64 65 73 63 7d | 0a 0a 5c 62 65 67 69 6e |uncdesc}|..\begin|
|000016f0| 7b 66 75 6e 63 64 65 73 | 63 7d 7b 72 6d 73 7d 7b |{funcdes|c}{rms}{|
|00001700| 66 72 61 67 6d 65 6e 74 | 5c 2c 20 77 69 64 74 68 |fragment|\, width|
|00001710| 7d 0a 52 65 74 75 72 6e | 20 74 68 65 20 72 6f 6f |}.Return| the roo|
|00001720| 74 2d 6d 65 61 6e 2d 73 | 71 75 61 72 65 20 6f 66 |t-mean-s|quare of|
|00001730| 20 74 68 65 20 66 72 61 | 67 6d 65 6e 74 2c 20 69 | the fra|gment, i|
|00001740| 2e 65 2e 0a 5c 69 66 74 | 65 78 69 0a 74 68 65 20 |.e..\ift|exi.the |
|00001750| 73 71 75 61 72 65 20 72 | 6f 6f 74 20 6f 66 20 74 |square r|oot of t|
|00001760| 68 65 20 71 75 6f 74 69 | 65 6e 74 20 6f 66 20 74 |he quoti|ent of t|
|00001770| 68 65 20 73 75 6d 20 6f | 66 20 61 6c 6c 20 73 71 |he sum o|f all sq|
|00001780| 75 61 72 65 64 20 73 61 | 6d 70 6c 65 20 76 61 6c |uared sa|mple val|
|00001790| 75 65 2c 0a 64 69 76 69 | 64 65 64 20 62 79 20 74 |ue,.divi|ded by t|
|000017a0| 68 65 20 73 75 6d 62 65 | 72 20 6f 66 20 73 61 6d |he sumbe|r of sam|
|000017b0| 70 6c 65 73 2e 0a 5c 65 | 6c 73 65 0a 25 20 69 6e |ples..\e|lse.% in|
|000017c0| 20 65 71 6e 3a 20 73 71 | 72 74 20 7b 20 73 75 6d | eqn: sq|rt { sum|
|000017d0| 20 53 20 73 75 62 20 69 | 20 73 75 70 20 32 20 20 | S sub i| sup 2 |
|000017e0| 6f 76 65 72 20 6e 20 7d | 0a 5c 62 65 67 69 6e 7b |over n }|.\begin{|
|000017f0| 64 69 73 70 6c 61 79 6d | 61 74 68 7d 0a 5c 63 61 |displaym|ath}.\ca|
|00001800| 74 63 6f 64 65 60 5f 3d | 38 0a 5c 73 71 72 74 7b |tcode`_=|8.\sqrt{|
|00001810| 5c 66 72 61 63 7b 5c 73 | 75 6d 7b 7b 53 5f 7b 69 |\frac{\s|um{{S_{i|
|00001820| 7d 7d 5e 7b 32 7d 7d 7d | 7b 6e 7d 7d 0a 5c 65 6e |}}^{2}}}|{n}}.\en|
|00001830| 64 7b 64 69 73 70 6c 61 | 79 6d 61 74 68 7d 0a 5c |d{displa|ymath}.\|
|00001840| 66 69 0a 54 68 69 73 20 | 69 73 20 61 20 6d 65 61 |fi.This |is a mea|
|00001850| 73 75 72 65 20 6f 66 20 | 74 68 65 20 70 6f 77 65 |sure of |the powe|
|00001860| 72 20 69 6e 20 61 6e 20 | 61 75 64 69 6f 20 73 69 |r in an |audio si|
|00001870| 67 6e 61 6c 2e 0a 5c 65 | 6e 64 7b 66 75 6e 63 64 |gnal..\e|nd{funcd|
|00001880| 65 73 63 7d 0a 0a 5c 62 | 65 67 69 6e 7b 66 75 6e |esc}..\b|egin{fun|
|00001890| 63 64 65 73 63 7d 7b 74 | 6f 6d 6f 6e 6f 7d 7b 66 |cdesc}{t|omono}{f|
|000018a0| 72 61 67 6d 65 6e 74 5c | 2c 20 77 69 64 74 68 5c |ragment\|, width\|
|000018b0| 2c 20 6c 66 61 63 74 6f | 72 5c 2c 20 72 66 61 63 |, lfacto|r\, rfac|
|000018c0| 74 6f 72 7d 20 0a 43 6f | 6e 76 65 72 74 20 61 20 |tor} .Co|nvert a |
|000018d0| 73 74 65 72 65 6f 20 66 | 72 61 67 6d 65 6e 74 20 |stereo f|ragment |
|000018e0| 74 6f 20 61 20 6d 6f 6e | 6f 20 66 72 61 67 6d 65 |to a mon|o fragme|
|000018f0| 6e 74 2e 20 20 54 68 65 | 20 6c 65 66 74 20 63 68 |nt. The| left ch|
|00001900| 61 6e 6e 65 6c 20 69 73 | 0a 6d 75 6c 74 69 70 6c |annel is|.multipl|
|00001910| 69 65 64 20 62 79 20 5c | 76 61 72 7b 6c 66 61 63 |ied by \|var{lfac|
|00001920| 74 6f 72 7d 20 61 6e 64 | 20 74 68 65 20 72 69 67 |tor} and| the rig|
|00001930| 68 74 20 63 68 61 6e 6e | 65 6c 20 62 79 20 5c 76 |ht chann|el by \v|
|00001940| 61 72 7b 72 66 61 63 74 | 6f 72 7d 0a 62 65 66 6f |ar{rfact|or}.befo|
|00001950| 72 65 20 61 64 64 69 6e | 67 20 74 68 65 20 74 77 |re addin|g the tw|
|00001960| 6f 20 63 68 61 6e 6e 65 | 6c 73 20 74 6f 20 67 69 |o channe|ls to gi|
|00001970| 76 65 20 61 20 6d 6f 6e | 6f 20 73 69 67 6e 61 6c |ve a mon|o signal|
|00001980| 2e 0a 5c 65 6e 64 7b 66 | 75 6e 63 64 65 73 63 7d |..\end{f|uncdesc}|
|00001990| 0a 0a 5c 62 65 67 69 6e | 7b 66 75 6e 63 64 65 73 |..\begin|{funcdes|
|000019a0| 63 7d 7b 74 6f 73 74 65 | 72 65 6f 7d 7b 66 72 61 |c}{toste|reo}{fra|
|000019b0| 67 6d 65 6e 74 5c 2c 20 | 77 69 64 74 68 5c 2c 20 |gment\, |width\, |
|000019c0| 6c 66 61 63 74 6f 72 5c | 2c 20 72 66 61 63 74 6f |lfactor\|, rfacto|
|000019d0| 72 7d 0a 47 65 6e 65 72 | 61 74 65 20 61 20 73 74 |r}.Gener|ate a st|
|000019e0| 65 72 65 6f 20 66 72 61 | 67 6d 65 6e 74 20 66 72 |ereo fra|gment fr|
|000019f0| 6f 6d 20 61 20 6d 6f 6e | 6f 20 66 72 61 67 6d 65 |om a mon|o fragme|
|00001a00| 6e 74 2e 20 20 45 61 63 | 68 20 70 61 69 72 20 6f |nt. Eac|h pair o|
|00001a10| 66 20 73 61 6d 70 6c 65 | 73 0a 69 6e 20 74 68 65 |f sample|s.in the|
|00001a20| 20 73 74 65 72 65 6f 20 | 66 72 61 67 6d 65 6e 74 | stereo |fragment|
|00001a30| 20 61 72 65 20 63 6f 6d | 70 75 74 65 64 20 66 72 | are com|puted fr|
|00001a40| 6f 6d 20 74 68 65 20 6d | 6f 6e 6f 20 73 61 6d 70 |om the m|ono samp|
|00001a50| 6c 65 2c 20 77 68 65 72 | 65 62 79 20 6c 65 66 74 |le, wher|eby left|
|00001a60| 0a 63 68 61 6e 6e 65 6c | 20 73 61 6d 70 6c 65 73 |.channel| samples|
|00001a70| 20 61 72 65 20 6d 75 6c | 74 69 70 6c 69 65 64 20 | are mul|tiplied |
|00001a80| 62 79 20 5c 76 61 72 7b | 6c 66 61 63 74 6f 72 7d |by \var{|lfactor}|
|00001a90| 20 61 6e 64 20 72 69 67 | 68 74 20 63 68 61 6e 6e | and rig|ht chann|
|00001aa0| 65 6c 0a 73 61 6d 70 6c | 65 73 20 62 79 20 5c 76 |el.sampl|es by \v|
|00001ab0| 61 72 7b 72 66 61 63 74 | 6f 72 7d 2e 0a 5c 65 6e |ar{rfact|or}..\en|
|00001ac0| 64 7b 66 75 6e 63 64 65 | 73 63 7d 0a 0a 5c 62 65 |d{funcde|sc}..\be|
|00001ad0| 67 69 6e 7b 66 75 6e 63 | 64 65 73 63 7d 7b 75 6c |gin{func|desc}{ul|
|00001ae0| 61 77 32 6c 69 6e 7d 7b | 66 72 61 67 6d 65 6e 74 |aw2lin}{|fragment|
|00001af0| 5c 2c 20 77 69 64 74 68 | 7d 0a 43 6f 6e 76 65 72 |\, width|}.Conver|
|00001b00| 74 20 73 6f 75 6e 64 20 | 66 72 61 67 6d 65 6e 74 |t sound |fragment|
|00001b10| 73 20 69 6e 20 55 4c 41 | 57 20 65 6e 63 6f 64 69 |s in ULA|W encodi|
|00001b20| 6e 67 20 74 6f 20 6c 69 | 6e 65 61 72 6c 79 20 65 |ng to li|nearly e|
|00001b30| 6e 63 6f 64 65 64 20 73 | 6f 75 6e 64 0a 66 72 61 |ncoded s|ound.fra|
|00001b40| 67 6d 65 6e 74 73 2e 20 | 20 55 4c 41 57 20 65 6e |gments. | ULAW en|
|00001b50| 63 6f 64 69 6e 67 20 61 | 6c 77 61 79 73 20 75 73 |coding a|lways us|
|00001b60| 65 73 20 38 20 62 69 74 | 73 20 73 61 6d 70 6c 65 |es 8 bit|s sample|
|00001b70| 73 2c 20 73 6f 20 5c 76 | 61 72 7b 77 69 64 74 68 |s, so \v|ar{width|
|00001b80| 7d 0a 72 65 66 65 72 73 | 20 6f 6e 6c 79 20 74 6f |}.refers| only to|
|00001b90| 20 74 68 65 20 73 61 6d | 70 6c 65 20 77 69 64 74 | the sam|ple widt|
|00001ba0| 68 20 6f 66 20 74 68 65 | 20 6f 75 74 70 75 74 20 |h of the| output |
|00001bb0| 66 72 61 67 6d 65 6e 74 | 20 68 65 72 65 2e 0a 5c |fragment| here..\|
|00001bc0| 65 6e 64 7b 66 75 6e 63 | 64 65 73 63 7d 0a 0a 4e |end{func|desc}..N|
|00001bd0| 6f 74 65 20 74 68 61 74 | 20 6f 70 65 72 61 74 69 |ote that| operati|
|00001be0| 6f 6e 73 20 73 75 63 68 | 20 61 73 20 5c 63 6f 64 |ons such| as \cod|
|00001bf0| 65 7b 6d 75 6c 7d 20 6f | 72 20 5c 63 6f 64 65 7b |e{mul} o|r \code{|
|00001c00| 6d 61 78 7d 20 6d 61 6b | 65 20 6e 6f 0a 64 69 73 |max} mak|e no.dis|
|00001c10| 74 69 6e 63 74 69 6f 6e | 20 62 65 74 77 65 65 6e |tinction| between|
|00001c20| 20 6d 6f 6e 6f 20 61 6e | 64 20 73 74 65 72 65 6f | mono an|d stereo|
|00001c30| 20 66 72 61 67 6d 65 6e | 74 73 2c 20 69 2e 65 2e | fragmen|ts, i.e.|
|00001c40| 5c 20 61 6c 6c 20 73 61 | 6d 70 6c 65 73 20 61 72 |\ all sa|mples ar|
|00001c50| 65 0a 74 72 65 61 74 65 | 64 20 65 71 75 61 6c 2e |e.treate|d equal.|
|00001c60| 20 20 49 66 20 74 68 69 | 73 20 69 73 20 61 20 70 | If thi|s is a p|
|00001c70| 72 6f 62 6c 65 6d 20 74 | 68 65 20 73 74 65 72 65 |roblem t|he stere|
|00001c80| 6f 20 66 72 61 67 6d 65 | 6e 74 20 73 68 6f 75 6c |o fragme|nt shoul|
|00001c90| 64 20 62 65 20 73 70 6c | 69 74 0a 69 6e 74 6f 20 |d be spl|it.into |
|00001ca0| 74 77 6f 20 6d 6f 6e 6f | 20 66 72 61 67 6d 65 6e |two mono| fragmen|
|00001cb0| 74 73 20 66 69 72 73 74 | 20 61 6e 64 20 72 65 63 |ts first| and rec|
|00001cc0| 6f 6d 62 69 6e 65 64 20 | 6c 61 74 65 72 2e 20 20 |ombined |later. |
|00001cd0| 48 65 72 65 20 69 73 20 | 61 6e 20 65 78 61 6d 70 |Here is |an examp|
|00001ce0| 6c 65 0a 6f 66 20 68 6f | 77 20 74 6f 20 64 6f 20 |le.of ho|w to do |
|00001cf0| 74 68 61 74 3a 0a 5c 62 | 63 6f 64 65 5c 62 65 67 |that:.\b|code\beg|
|00001d00| 69 6e 7b 76 65 72 62 61 | 74 69 6d 7d 0a 64 65 66 |in{verba|tim}.def|
|00001d10| 20 6d 75 6c 5f 73 74 65 | 72 65 6f 28 73 61 6d 70 | mul_ste|reo(samp|
|00001d20| 6c 65 2c 20 77 69 64 74 | 68 2c 20 6c 66 61 63 74 |le, widt|h, lfact|
|00001d30| 6f 72 2c 20 72 66 61 63 | 74 6f 72 29 3a 0a 20 20 |or, rfac|tor):. |
|00001d40| 20 20 6c 73 61 6d 70 6c | 65 20 3d 20 61 75 64 69 | lsampl|e = audi|
|00001d50| 6f 6f 70 2e 74 6f 6d 6f | 6e 6f 28 73 61 6d 70 6c |oop.tomo|no(sampl|
|00001d60| 65 2c 20 77 69 64 74 68 | 2c 20 31 2c 20 30 29 0a |e, width|, 1, 0).|
|00001d70| 20 20 20 20 72 73 61 6d | 70 6c 65 20 3d 20 61 75 | rsam|ple = au|
|00001d80| 64 69 6f 6f 70 2e 74 6f | 6d 6f 6e 6f 28 73 61 6d |dioop.to|mono(sam|
|00001d90| 70 6c 65 2c 20 77 69 64 | 74 68 2c 20 30 2c 20 31 |ple, wid|th, 0, 1|
|00001da0| 29 0a 20 20 20 20 6c 73 | 61 6d 70 6c 65 20 3d 20 |). ls|ample = |
|00001db0| 61 75 64 69 6f 6f 70 2e | 6d 75 6c 28 73 61 6d 70 |audioop.|mul(samp|
|00001dc0| 6c 65 2c 20 77 69 64 74 | 68 2c 20 6c 66 61 63 74 |le, widt|h, lfact|
|00001dd0| 6f 72 29 0a 20 20 20 20 | 72 73 61 6d 70 6c 65 20 |or). |rsample |
|00001de0| 3d 20 61 75 64 69 6f 6f | 70 2e 6d 75 6c 28 73 61 |= audioo|p.mul(sa|
|00001df0| 6d 70 6c 65 2c 20 77 69 | 64 74 68 2c 20 72 66 61 |mple, wi|dth, rfa|
|00001e00| 63 74 6f 72 29 0a 20 20 | 20 20 6c 73 61 6d 70 6c |ctor). | lsampl|
|00001e10| 65 20 3d 20 61 75 64 69 | 6f 6f 70 2e 74 6f 73 74 |e = audi|oop.tost|
|00001e20| 65 72 65 6f 28 6c 73 61 | 6d 70 6c 65 2c 20 77 69 |ereo(lsa|mple, wi|
|00001e30| 64 74 68 2c 20 31 2c 20 | 30 29 0a 20 20 20 20 72 |dth, 1, |0). r|
|00001e40| 73 61 6d 70 6c 65 20 3d | 20 61 75 64 69 6f 6f 70 |sample =| audioop|
|00001e50| 2e 74 6f 73 74 65 72 65 | 6f 28 72 73 61 6d 70 6c |.tostere|o(rsampl|
|00001e60| 65 2c 20 77 69 64 74 68 | 2c 20 30 2c 20 31 29 0a |e, width|, 0, 1).|
|00001e70| 20 20 20 20 72 65 74 75 | 72 6e 20 61 75 64 69 6f | retu|rn audio|
|00001e80| 6f 70 2e 61 64 64 28 6c | 73 61 6d 70 6c 65 2c 20 |op.add(l|sample, |
|00001e90| 72 73 61 6d 70 6c 65 2c | 20 77 69 64 74 68 29 0a |rsample,| width).|
|00001ea0| 5c 65 6e 64 7b 76 65 72 | 62 61 74 69 6d 7d 5c 65 |\end{ver|batim}\e|
|00001eb0| 63 6f 64 65 0a 0a 49 66 | 20 79 6f 75 20 75 73 65 |code..If| you use|
|00001ec0| 20 74 68 65 20 41 44 50 | 43 4d 20 63 6f 64 65 72 | the ADP|CM coder|
|00001ed0| 20 74 6f 20 62 75 69 6c | 64 20 6e 65 74 77 6f 72 | to buil|d networ|
|00001ee0| 6b 20 70 61 63 6b 65 74 | 73 20 61 6e 64 20 79 6f |k packet|s and yo|
|00001ef0| 75 20 77 61 6e 74 20 79 | 6f 75 72 0a 70 72 6f 74 |u want y|our.prot|
|00001f00| 6f 63 6f 6c 20 74 6f 20 | 62 65 20 73 74 61 74 65 |ocol to |be state|
|00001f10| 6c 65 73 73 20 28 69 2e | 65 2e 5c 20 74 6f 20 62 |less (i.|e.\ to b|
|00001f20| 65 20 61 62 6c 65 20 74 | 6f 20 74 6f 6c 65 72 61 |e able t|o tolera|
|00001f30| 74 65 20 70 61 63 6b 65 | 74 20 6c 6f 73 73 29 0a |te packe|t loss).|
|00001f40| 79 6f 75 20 73 68 6f 75 | 6c 64 20 6e 6f 74 20 6f |you shou|ld not o|
|00001f50| 6e 6c 79 20 74 72 61 6e | 73 6d 69 74 20 74 68 65 |nly tran|smit the|
|00001f60| 20 64 61 74 61 20 62 75 | 74 20 61 6c 73 6f 20 74 | data bu|t also t|
|00001f70| 68 65 20 73 74 61 74 65 | 2e 20 20 4e 6f 74 65 20 |he state|. Note |
|00001f80| 74 68 61 74 0a 79 6f 75 | 20 73 68 6f 75 6c 64 20 |that.you| should |
|00001f90| 73 65 6e 64 20 74 68 65 | 20 5c 76 61 72 7b 69 6e |send the| \var{in|
|00001fa0| 69 74 69 61 6c 7d 20 73 | 74 61 74 65 20 28 74 68 |itial} s|tate (th|
|00001fb0| 65 20 6f 6e 65 20 79 6f | 75 20 70 61 73 73 65 64 |e one yo|u passed|
|00001fc0| 20 74 6f 0a 5c 63 6f 64 | 65 7b 6c 69 6e 32 61 64 | to.\cod|e{lin2ad|
|00001fd0| 70 63 6d 7d 29 20 61 6c | 6f 6e 67 20 74 6f 20 74 |pcm}) al|ong to t|
|00001fe0| 68 65 20 64 65 63 6f 64 | 65 72 2c 20 6e 6f 74 20 |he decod|er, not |
|00001ff0| 74 68 65 20 66 69 6e 61 | 6c 20 73 74 61 74 65 20 |the fina|l state |
|00002000| 28 61 73 20 72 65 74 75 | 72 6e 65 64 20 62 79 0a |(as retu|rned by.|
|00002010| 74 68 65 20 63 6f 64 65 | 72 29 2e 20 20 49 66 20 |the code|r). If |
|00002020| 79 6f 75 20 77 61 6e 74 | 20 74 6f 20 75 73 65 20 |you want| to use |
|00002030| 5c 63 6f 64 65 7b 73 74 | 72 75 63 74 7d 20 74 6f |\code{st|ruct} to|
|00002040| 20 73 74 6f 72 65 20 74 | 68 65 20 73 74 61 74 65 | store t|he state|
|00002050| 20 69 6e 0a 62 69 6e 61 | 72 79 20 79 6f 75 20 63 | in.bina|ry you c|
|00002060| 61 6e 20 63 6f 64 65 20 | 74 68 65 20 66 69 72 73 |an code |the firs|
|00002070| 74 20 65 6c 65 6d 65 6e | 74 20 28 74 68 65 20 70 |t elemen|t (the p|
|00002080| 72 65 64 69 63 74 65 64 | 20 76 61 6c 75 65 29 20 |redicted| value) |
|00002090| 69 6e 20 31 36 20 62 69 | 74 73 0a 61 6e 64 20 74 |in 16 bi|ts.and t|
|000020a0| 68 65 20 73 65 63 6f 6e | 64 20 28 74 68 65 20 64 |he secon|d (the d|
|000020b0| 65 6c 74 61 20 69 6e 64 | 65 78 29 20 69 6e 20 38 |elta ind|ex) in 8|
|000020c0| 2e 0a 0a 54 68 65 20 41 | 44 50 43 4d 20 63 6f 64 |...The A|DPCM cod|
|000020d0| 65 72 73 20 68 61 76 65 | 20 6e 65 76 65 72 20 62 |ers have| never b|
|000020e0| 65 65 6e 20 74 72 69 65 | 64 20 61 67 61 69 6e 73 |een trie|d agains|
|000020f0| 74 20 6f 74 68 65 72 20 | 41 44 50 43 4d 20 63 6f |t other |ADPCM co|
|00002100| 64 65 72 73 2c 0a 6f 6e | 6c 79 20 61 67 61 69 6e |ders,.on|ly again|
|00002110| 73 74 20 74 68 65 6d 73 | 65 6c 76 65 73 2e 20 20 |st thems|elves. |
|00002120| 49 74 20 63 6f 75 6c 64 | 20 77 65 6c 6c 20 62 65 |It could| well be|
|00002130| 20 74 68 61 74 20 49 20 | 6d 69 73 69 6e 74 65 72 | that I |misinter|
|00002140| 70 72 65 74 65 64 20 74 | 68 65 0a 73 74 61 6e 64 |preted t|he.stand|
|00002150| 61 72 64 73 20 69 6e 20 | 77 68 69 63 68 20 63 61 |ards in |which ca|
|00002160| 73 65 20 74 68 65 79 20 | 77 69 6c 6c 20 6e 6f 74 |se they |will not|
|00002170| 20 62 65 20 69 6e 74 65 | 72 6f 70 65 72 61 62 6c | be inte|roperabl|
|00002180| 65 20 77 69 74 68 20 74 | 68 65 0a 72 65 73 70 65 |e with t|he.respe|
|00002190| 63 74 69 76 65 20 73 74 | 61 6e 64 61 72 64 73 2e |ctive st|andards.|
|000021a0| 0a 0a 54 68 65 20 5c 63 | 6f 64 65 7b 66 69 6e 64 |..The \c|ode{find|
|000021b0| 2e 2e 2e 7d 20 72 6f 75 | 74 69 6e 65 73 20 6d 69 |...} rou|tines mi|
|000021c0| 67 68 74 20 6c 6f 6f 6b | 20 61 20 62 69 74 20 66 |ght look| a bit f|
|000021d0| 75 6e 6e 79 20 61 74 20 | 66 69 72 73 74 20 73 69 |unny at |first si|
|000021e0| 67 68 74 2e 0a 54 68 65 | 79 20 61 72 65 20 70 72 |ght..The|y are pr|
|000021f0| 69 6d 61 72 69 6c 79 20 | 6d 65 61 6e 74 20 74 6f |imarily |meant to|
|00002200| 20 64 6f 20 65 63 68 6f | 20 63 61 6e 63 65 6c 6c | do echo| cancell|
|00002210| 61 74 69 6f 6e 2e 20 20 | 41 20 72 65 61 73 6f 6e |ation. |A reason|
|00002220| 61 62 6c 79 0a 66 61 73 | 74 20 77 61 79 20 74 6f |ably.fas|t way to|
|00002230| 20 64 6f 20 74 68 69 73 | 20 69 73 20 74 6f 20 70 | do this| is to p|
|00002240| 69 63 6b 20 74 68 65 20 | 6d 6f 73 74 20 65 6e 65 |ick the |most ene|
|00002250| 72 67 65 74 69 63 20 70 | 69 65 63 65 20 6f 66 20 |rgetic p|iece of |
|00002260| 74 68 65 20 6f 75 74 70 | 75 74 0a 73 61 6d 70 6c |the outp|ut.sampl|
|00002270| 65 2c 20 6c 6f 63 61 74 | 65 20 74 68 61 74 20 69 |e, locat|e that i|
|00002280| 6e 20 74 68 65 20 69 6e | 70 75 74 20 73 61 6d 70 |n the in|put samp|
|00002290| 6c 65 20 61 6e 64 20 73 | 75 62 74 72 61 63 74 20 |le and s|ubtract |
|000022a0| 74 68 65 20 77 68 6f 6c | 65 20 6f 75 74 70 75 74 |the whol|e output|
|000022b0| 0a 73 61 6d 70 6c 65 20 | 66 72 6f 6d 20 74 68 65 |.sample |from the|
|000022c0| 20 69 6e 70 75 74 20 73 | 61 6d 70 6c 65 3a 0a 5c | input s|ample:.\|
|000022d0| 62 63 6f 64 65 5c 62 65 | 67 69 6e 7b 76 65 72 62 |bcode\be|gin{verb|
|000022e0| 61 74 69 6d 7d 0a 64 65 | 66 20 65 63 68 6f 63 61 |atim}.de|f echoca|
|000022f0| 6e 63 65 6c 28 6f 75 74 | 70 75 74 64 61 74 61 2c |ncel(out|putdata,|
|00002300| 20 69 6e 70 75 74 64 61 | 74 61 29 3a 0a 20 20 20 | inputda|ta):. |
|00002310| 20 70 6f 73 20 3d 20 61 | 75 64 69 6f 6f 70 2e 66 | pos = a|udioop.f|
|00002320| 69 6e 64 6d 61 78 28 6f | 75 74 70 75 74 64 61 74 |indmax(o|utputdat|
|00002330| 61 2c 20 38 30 30 29 20 | 20 20 20 23 20 6f 6e 65 |a, 800) | # one|
|00002340| 20 74 65 6e 74 68 20 73 | 65 63 6f 6e 64 0a 20 20 | tenth s|econd. |
|00002350| 20 20 6f 75 74 5f 74 65 | 73 74 20 3d 20 6f 75 74 | out_te|st = out|
|00002360| 70 75 74 64 61 74 61 5b | 70 6f 73 2a 32 3a 5d 0a |putdata[|pos*2:].|
|00002370| 20 20 20 20 69 6e 5f 74 | 65 73 74 20 3d 20 69 6e | in_t|est = in|
|00002380| 70 75 74 64 61 74 61 5b | 70 6f 73 2a 32 3a 5d 0a |putdata[|pos*2:].|
|00002390| 20 20 20 20 69 70 6f 73 | 2c 20 66 61 63 74 6f 72 | ipos|, factor|
|000023a0| 20 3d 20 61 75 64 69 6f | 6f 70 2e 66 69 6e 64 66 | = audio|op.findf|
|000023b0| 69 74 28 69 6e 5f 74 65 | 73 74 2c 20 6f 75 74 5f |it(in_te|st, out_|
|000023c0| 74 65 73 74 29 0a 20 20 | 20 20 23 20 4f 70 74 69 |test). | # Opti|
|000023d0| 6f 6e 61 6c 20 28 66 6f | 72 20 62 65 74 74 65 72 |onal (fo|r better|
|000023e0| 20 63 61 6e 63 65 6c 6c | 61 74 69 6f 6e 29 3a 0a | cancell|ation):.|
|000023f0| 20 20 20 20 23 20 66 61 | 63 74 6f 72 20 3d 20 61 | # fa|ctor = a|
|00002400| 75 64 69 6f 6f 70 2e 66 | 69 6e 64 66 61 63 74 6f |udioop.f|indfacto|
|00002410| 72 28 69 6e 5f 74 65 73 | 74 5b 69 70 6f 73 2a 32 |r(in_tes|t[ipos*2|
|00002420| 3a 69 70 6f 73 2a 32 2b | 6c 65 6e 28 6f 75 74 5f |:ipos*2+|len(out_|
|00002430| 74 65 73 74 29 5d 2c 20 | 0a 20 20 20 20 23 20 20 |test)], |. # |
|00002440| 20 20 20 20 20 20 20 20 | 20 20 20 20 6f 75 74 5f | | out_|
|00002450| 74 65 73 74 29 0a 20 20 | 20 20 70 72 65 66 69 6c |test). | prefil|
|00002460| 6c 20 3d 20 27 5c 30 27 | 2a 28 70 6f 73 2b 69 70 |l = '\0'|*(pos+ip|
|00002470| 6f 73 29 2a 32 0a 20 20 | 20 20 70 6f 73 74 66 69 |os)*2. | postfi|
|00002480| 6c 6c 20 3d 20 27 5c 30 | 27 2a 28 6c 65 6e 28 69 |ll = '\0|'*(len(i|
|00002490| 6e 70 75 74 64 61 74 61 | 29 2d 6c 65 6e 28 70 72 |nputdata|)-len(pr|
|000024a0| 65 66 69 6c 6c 29 2d 6c | 65 6e 28 6f 75 74 70 75 |efill)-l|en(outpu|
|000024b0| 74 64 61 74 61 29 29 0a | 20 20 20 20 6f 75 74 70 |tdata)).| outp|
|000024c0| 75 74 64 61 74 61 20 3d | 20 70 72 65 66 69 6c 6c |utdata =| prefill|
|000024d0| 20 2b 20 61 75 64 69 6f | 6f 70 2e 6d 75 6c 28 6f | + audio|op.mul(o|
|000024e0| 75 74 70 75 74 64 61 74 | 61 2c 32 2c 2d 66 61 63 |utputdat|a,2,-fac|
|000024f0| 74 6f 72 29 20 2b 20 70 | 6f 73 74 66 69 6c 6c 0a |tor) + p|ostfill.|
|00002500| 20 20 20 20 72 65 74 75 | 72 6e 20 61 75 64 69 6f | retu|rn audio|
|00002510| 6f 70 2e 61 64 64 28 69 | 6e 70 75 74 64 61 74 61 |op.add(i|nputdata|
|00002520| 2c 20 6f 75 74 70 75 74 | 64 61 74 61 2c 20 32 29 |, output|data, 2)|
|00002530| 0a 5c 65 6e 64 7b 76 65 | 72 62 61 74 69 6d 7d 5c |.\end{ve|rbatim}\|
|00002540| 65 63 6f 64 65 0a | |ecode. | |
+--------+-------------------------+-------------------------+--------+--------+