Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(26)

Side by Side Diff: Doc/library/audioop.rst

Issue 18758: Fix internal references in the documentation
Patch Set: Created 6 years, 5 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Doc/library/asyncore.rst ('k') | Doc/library/calendar.rst » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 :mod:`audioop` --- Manipulate raw audio data 1 :mod:`audioop` --- Manipulate raw audio data
2 ============================================ 2 ============================================
3 3
4 .. module:: audioop 4 .. module:: audioop
5 :synopsis: Manipulate raw audio data. 5 :synopsis: Manipulate raw audio data.
6 6
7 7
8 The :mod:`audioop` module contains some useful operations on sound fragments. 8 The :mod:`audioop` module contains some useful operations on sound fragments.
9 It operates on sound fragments consisting of signed integer samples 8, 16 or 32 9 It operates on sound fragments consisting of signed integer samples 8, 16 or 32
10 bits wide, stored in bytes objects. All scalar items are integers, unless 10 bits wide, stored in bytes objects. All scalar items are integers, unless
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 rsample = audioop.mul(rsample, width, rfactor) 234 rsample = audioop.mul(rsample, width, rfactor)
235 lsample = audioop.tostereo(lsample, width, 1, 0) 235 lsample = audioop.tostereo(lsample, width, 1, 0)
236 rsample = audioop.tostereo(rsample, width, 0, 1) 236 rsample = audioop.tostereo(rsample, width, 0, 1)
237 return audioop.add(lsample, rsample, width) 237 return audioop.add(lsample, rsample, width)
238 238
239 If you use the ADPCM coder to build network packets and you want your protocol 239 If you use the ADPCM coder to build network packets and you want your protocol
240 to be stateless (i.e. to be able to tolerate packet loss) you should not only 240 to be stateless (i.e. to be able to tolerate packet loss) you should not only
241 transmit the data but also the state. Note that you should send the *initial* 241 transmit the data but also the state. Note that you should send the *initial*
242 state (the one you passed to :func:`lin2adpcm`) along to the decoder, not the 242 state (the one you passed to :func:`lin2adpcm`) along to the decoder, not the
243 final state (as returned by the coder). If you want to use 243 final state (as returned by the coder). If you want to use
244 :func:`struct.struct` to store the state in binary you can code the first 244 :class:`struct.Struct` to store the state in binary you can code the first
245 element (the predicted value) in 16 bits and the second (the delta index) in 8. 245 element (the predicted value) in 16 bits and the second (the delta index) in 8.
246 246
247 The ADPCM coders have never been tried against other ADPCM coders, only against 247 The ADPCM coders have never been tried against other ADPCM coders, only against
248 themselves. It could well be that I misinterpreted the standards in which case 248 themselves. It could well be that I misinterpreted the standards in which case
249 they will not be interoperable with the respective standards. 249 they will not be interoperable with the respective standards.
250 250
251 The :func:`find\*` routines might look a bit funny at first sight. They are 251 The :func:`find\*` routines might look a bit funny at first sight. They are
252 primarily meant to do echo cancellation. A reasonably fast way to do this is to 252 primarily meant to do echo cancellation. A reasonably fast way to do this is to
253 pick the most energetic piece of the output sample, locate that in the input 253 pick the most energetic piece of the output sample, locate that in the input
254 sample and subtract the whole output sample from the input sample:: 254 sample and subtract the whole output sample from the input sample::
255 255
256 def echocancel(outputdata, inputdata): 256 def echocancel(outputdata, inputdata):
257 pos = audioop.findmax(outputdata, 800) # one tenth second 257 pos = audioop.findmax(outputdata, 800) # one tenth second
258 out_test = outputdata[pos*2:] 258 out_test = outputdata[pos*2:]
259 in_test = inputdata[pos*2:] 259 in_test = inputdata[pos*2:]
260 ipos, factor = audioop.findfit(in_test, out_test) 260 ipos, factor = audioop.findfit(in_test, out_test)
261 # Optional (for better cancellation): 261 # Optional (for better cancellation):
262 # factor = audioop.findfactor(in_test[ipos*2:ipos*2+len(out_test)], 262 # factor = audioop.findfactor(in_test[ipos*2:ipos*2+len(out_test)],
263 # out_test) 263 # out_test)
264 prefill = '\0'*(pos+ipos)*2 264 prefill = '\0'*(pos+ipos)*2
265 postfill = '\0'*(len(inputdata)-len(prefill)-len(outputdata)) 265 postfill = '\0'*(len(inputdata)-len(prefill)-len(outputdata))
266 outputdata = prefill + audioop.mul(outputdata,2,-factor) + postfill 266 outputdata = prefill + audioop.mul(outputdata,2,-factor) + postfill
267 return audioop.add(inputdata, outputdata, 2) 267 return audioop.add(inputdata, outputdata, 2)
268 268
OLDNEW
« no previous file with comments | « Doc/library/asyncore.rst ('k') | Doc/library/calendar.rst » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+