11\section {Built-in module \sectcode {audioop} }
22\bimodindex {audioop}
33
4- The audioop module contains some useful operations on sound fragments.
5- It operates on sound fragments consisting of signed integer samples of
4+ The \code { audioop} module contains some useful operations on sound fragments.
5+ It operates on sound fragments consisting of signed integer samples
668, 16 or 32 bits wide, stored in Python strings. This is the same
77format as used by the \code {al} and \code {sunaudiodev} modules. All
88scalar items are integers, unless specified otherwise.
@@ -19,7 +19,7 @@ \section{Built-in module \sectcode{audioop}}
1919\end {excdesc }
2020
2121\begin {funcdesc }{add}{fragment1\, fragment2\, width}
22- This function returns a fragment that is the addition of the two samples
22+ This function returns a fragment which is the addition of the two samples
2323passed as parameters. \var {width} is the sample width in bytes, either
2424\code {1}, \code {2} or \code {4}. Both fragments should have the same length.
2525\end {funcdesc }
@@ -60,16 +60,16 @@ \section{Built-in module \sectcode{audioop}}
6060\begin {funcdesc }{findfactor}{fragment\, reference}
6161This routine (which only accepts 2-byte sample fragments) calculates a
6262factor \var {F} such that \code {rms(add(fragment, mul(reference, -F)))}
63- is minimal, i.e. it calculates the factor with which you should
64- multiply \var {reference} to make it match as good as possible to
63+ is minimal, i.e.\ it calculates the factor with which you should
64+ multiply \var {reference} to make it match as well as possible to
6565\var {fragment}. The fragments should be the same size.
6666
6767The time taken by this routine is proportional to \code {len(fragment)}.
6868\end {funcdesc }
6969
7070\begin {funcdesc }{findfit}{fragment\, reference}
7171This routine (which only accepts 2-byte sample fragments) tries to
72- match \var {reference} as good as possible to a portion of
72+ match \var {reference} as well as possible to a portion of
7373\var {fragment} (which should be the longer fragment). It
7474(conceptually) does this by taking slices out of \var {fragment}, using
7575\code {findfactor} to compute the best match, and minimizing the
@@ -81,8 +81,8 @@ \section{Built-in module \sectcode{audioop}}
8181
8282\begin {funcdesc }{findmax}{fragment\, length}
8383This routine (which only accepts 2-byte sample fragments) searches
84- \var {fragment} for a slice of length \var {length} samples (not bytes!)
85- with maximum energy, i.e. it returns \var {i} for which
84+ \var {fragment} for a slice of length \var {length} samples (not bytes!)\
85+ with maximum energy, i.e.\ it returns \var {i} for which
8686\code {rms(fragment[i*2:(i+length)*2])} is maximal.
8787
8888The routine takes time proportional to \code {len(fragment)}.
@@ -140,7 +140,7 @@ \section{Built-in module \sectcode{audioop}}
140140\end {funcdesc }
141141
142142\begin {funcdesc }{mul}{fragment\, width\, factor}
143- Mul returns a fragment that has all samples in the original framgent
143+ Return a fragment that has all samples in the original framgent
144144multiplied by the floating-point value \var {factor}. Overflow is
145145silently ignored.
146146\end {funcdesc }
@@ -150,25 +150,6 @@ \section{Built-in module \sectcode{audioop}}
150150modified fragment.
151151\end {funcdesc }
152152
153- \begin {funcdesc }{tomono}{fragment\, width\, lfactor\, rfactor}
154- This function converts a stereo fragment to a mono fragment. The left
155- channel is multiplied by \var {lfactor} and the right channel by
156- \var {rfactor} before adding the two channels to give a mono signal.
157- \end {funcdesc }
158-
159- \begin {funcdesc }{tostereo}{fragment\, width\, lfactor\, rfactor}
160- This function generates a stereo fragment from a mono fragment. Each
161- pair of samples in the stereo fragment are computed from the mono
162- sample, whereby left channel samples are multiplied by \var {lfactor}
163- and right channel samples by \var {rfactor}.
164- \end {funcdesc }
165-
166- \begin {funcdesc }{mul}{fragment\, width\, factor}
167- Mul returns a fragment that has all samples in the original framgent
168- multiplied by the floating-point value \var {factor}. Overflow is
169- silently ignored.
170- \end {funcdesc }
171-
172153\begin {funcdesc }{rms}{fragment\, width\, factor}
173154Returns the root-mean-square of the fragment, i.e.
174155\iftexi
@@ -184,14 +165,27 @@ \section{Built-in module \sectcode{audioop}}
184165This is a measure of the power in an audio signal.
185166\end {funcdesc }
186167
168+ \begin {funcdesc }{tomono}{fragment\, width\, lfactor\, rfactor}
169+ This function converts a stereo fragment to a mono fragment. The left
170+ channel is multiplied by \var {lfactor} and the right channel by
171+ \var {rfactor} before adding the two channels to give a mono signal.
172+ \end {funcdesc }
173+
174+ \begin {funcdesc }{tostereo}{fragment\, width\, lfactor\, rfactor}
175+ This function generates a stereo fragment from a mono fragment. Each
176+ pair of samples in the stereo fragment are computed from the mono
177+ sample, whereby left channel samples are multiplied by \var {lfactor}
178+ and right channel samples by \var {rfactor}.
179+ \end {funcdesc }
180+
187181\begin {funcdesc }{ulaw2lin}{fragment\, width}
188182This function converts sound fragments in ULAW encoding to linearly
189183encoded sound fragments. ULAW encoding always uses 8 bits samples, so
190184\var {width} refers only to the sample width of the output fragment here.
191185\end {funcdesc }
192186
193187Note that operations such as \code {mul} or \code {max} make no
194- distinction between mono and stereo fragments, i.e. all samples are
188+ distinction between mono and stereo fragments, i.e.\ all samples are
195189treated equal. If this is a problem the stereo fragment should be split
196190into two mono fragments first and recombined later. Here is an example
197191of how to do that:
@@ -207,10 +201,10 @@ \section{Built-in module \sectcode{audioop}}
207201\end {verbatim }\ecode
208202
209203If you use the ADPCM coder to build network packets and you want your
210- protocol to be stateless (i.e. to be able to tolerate packet loss)
204+ protocol to be stateless (i.e.\ to be able to tolerate packet loss)
211205you should not only transmit the data but also the state. Note that
212206you should send the \var {initial} state (the one you passed to
213- lin2adpcm) along to the decoder, not the final state (as returned by
207+ \code { lin2adpcm} ) along to the decoder, not the final state (as returned by
214208the coder). If you want to use \code {struct} to store the state in
215209binary you can code the first element (the predicted value) in 16 bits
216210and the second (the delta index) in 8.
0 commit comments