Built-in module audioop

The audioop module contains some useful operations on sound fragments. It operates on sound fragments consisting of signed integer samples of 8, 16 or 32 bits wide, stored in Python strings. This is the same format as used by the al and sunaudiodev modules. All scalar items are integers, unless specified otherwise.

A few of the more complicated operations only take 16-bit samples, otherwise the sample size (in bytes) is always a parameter of the operation.

The module defines the following variables and functions:


#excdesc2929#


#funcdesc2932#


#funcdesc2940#


#funcdesc2948#


#funcdesc2953#


#funcdesc2957#


#funcdesc2961#


#funcdesc2965#


#funcdesc2969#


#funcdesc2978#


#funcdesc2990#


#funcdesc2999#


#funcdesc3004#


#funcdesc3008#


#funcdesc3018#


#funcdesc3022#


#funcdesc3026#


#funcdesc3030#


#funcdesc3035#


#funcdesc3039#


#funcdesc3044#


#funcdesc3048#


#funcdesc3054#


#funcdesc3060#


#funcdesc3065#


#funcdesc3074#

Note that operations such as mul or max make no distinction between mono and stereo fragments, i.e. all samples are treated equal. If this is a problem the stereo fragment should be split into two mono fragments first and recombined later. Here is an example of how to do that:

verbatim167#

If you use the ADPCM coder to build network packets and you want your protocol to be stateless (i.e. to be able to tolerate packet loss) you should not only transmit the data but also the state. Note that you should send the initial state (the one you passed to lin2adpcm) along to the decoder, not the final state (as returned by the coder). If you want to use struct to store the state in binary you can code the first element (the predicted value) in 16 bits and the second (the delta index) in 8.

The ADPCM coders have never been tried against other ADPCM coders, only against themselves. It could well be that I misinterpreted the standards in which case they will not be interoperable with the respective standards.

The find... routines might look a bit funny at first sight. They are primarily meant for doing echo cancellation. A reasonably fast way to do this is to pick the most energetic piece of the output sample, locate that in the input sample and subtract the whole output sample from the input sample:

verbatim168#