diff options
author | Guido van Rossum <guido@python.org> | 1995-03-17 16:07:09 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1995-03-17 16:07:09 (GMT) |
commit | 470be14c8aa23a35a1f4d1f1260a66a85d3f3cd9 (patch) | |
tree | 4fd0b8eda81e63366598e55362ceac85adafccb4 /Doc/libaudioop.tex | |
parent | 7760cdea81166b7741561043c58dae171811fb2f (diff) | |
download | cpython-470be14c8aa23a35a1f4d1f1260a66a85d3f3cd9.zip cpython-470be14c8aa23a35a1f4d1f1260a66a85d3f3cd9.tar.gz cpython-470be14c8aa23a35a1f4d1f1260a66a85d3f3cd9.tar.bz2 |
mass changes; fix titles; add examples; correct typos; clarifications;
unified style; etc.
Diffstat (limited to 'Doc/libaudioop.tex')
-rw-r--r-- | Doc/libaudioop.tex | 150 |
1 files changed, 75 insertions, 75 deletions
diff --git a/Doc/libaudioop.tex b/Doc/libaudioop.tex index 03e074d..6a74a0b 100644 --- a/Doc/libaudioop.tex +++ b/Doc/libaudioop.tex @@ -1,4 +1,4 @@ -\section{Built-in module \sectcode{audioop}} +\section{Built-in Module \sectcode{audioop}} \bimodindex{audioop} The \code{audioop} module contains some useful operations on sound fragments. @@ -19,139 +19,139 @@ per sample, etc. \end{excdesc} \begin{funcdesc}{add}{fragment1\, fragment2\, width} -This function returns a fragment which is the addition of the two samples -passed as parameters. \var{width} is the sample width in bytes, either -\code{1}, \code{2} or \code{4}. Both fragments should have the same length. +Return a fragment which is the addition of the two samples passed as +parameters. \var{width} is the sample width in bytes, either +\code{1}, \code{2} or \code{4}. Both fragments should have the same +length. \end{funcdesc} \begin{funcdesc}{adpcm2lin}{adpcmfragment\, width\, state} -This routine decodes an Intel/DVI ADPCM coded fragment to a linear -fragment. See the description of \code{lin2adpcm} for details on ADPCM -coding. The routine returns a tuple -\code{(\var{sample}, \var{newstate})} -where the sample has the width specified in \var{width}. +Decode an Intel/DVI ADPCM coded fragment to a linear fragment. See +the description of \code{lin2adpcm} for details on ADPCM coding. +Return a tuple \code{(\var{sample}, \var{newstate})} where the sample +has the width specified in \var{width}. \end{funcdesc} \begin{funcdesc}{adpcm32lin}{adpcmfragment\, width\, state} -This routine decodes an alternative 3-bit ADPCM code. See -\code{lin2adpcm3} for details. +Decode an alternative 3-bit ADPCM code. See \code{lin2adpcm3} for +details. \end{funcdesc} \begin{funcdesc}{avg}{fragment\, width} -This function returns the average over all samples in the fragment. +Return the average over all samples in the fragment. \end{funcdesc} \begin{funcdesc}{avgpp}{fragment\, width} -This function returns the average peak-peak value over all samples in -the fragment. No filtering is done, so the usefulness of this routine -is questionable. +Return the average peak-peak value over all samples in the fragment. +No filtering is done, so the usefulness of this routine is +questionable. \end{funcdesc} \begin{funcdesc}{bias}{fragment\, width\, bias} -This function returns a fragment that is the original fragment with a -bias added to each sample. +Return a fragment that is the original fragment with a bias added to +each sample. \end{funcdesc} \begin{funcdesc}{cross}{fragment\, width} -This function returns the number of zero crossings in the fragment -passed as an argument. +Return the number of zero crossings in the fragment passed as an +argument. \end{funcdesc} \begin{funcdesc}{findfactor}{fragment\, reference} -This routine (which only accepts 2-byte sample fragments) calculates a -factor \var{F} such that \code{rms(add(fragment, mul(reference, -F)))} -is minimal, i.e.\ it calculates the factor with which you should -multiply \var{reference} to make it match as well as possible to -\var{fragment}. The fragments should be the same size. +Return a factor \var{F} such that +\code{rms(add(fragment, mul(reference, -F)))} is minimal, i.e., +return the factor with which you should multiply \var{reference} to +make it match as well as possible to \var{fragment}. The fragments +should both contain 2-byte samples. The time taken by this routine is proportional to \code{len(fragment)}. \end{funcdesc} \begin{funcdesc}{findfit}{fragment\, reference} -This routine (which only accepts 2-byte sample fragments) tries to -match \var{reference} as well as possible to a portion of -\var{fragment} (which should be the longer fragment). It -(conceptually) does this by taking slices out of \var{fragment}, using +This routine (which only accepts 2-byte sample fragments) + +Try to match \var{reference} as well as possible to a portion of +\var{fragment} (which should be the longer fragment). This is +(conceptually) done by taking slices out of \var{fragment}, using \code{findfactor} to compute the best match, and minimizing the -result. -It returns a tuple \code{(\var{offset}, \var{factor})} with \var{offset} the +result. The fragments should both contain 2-byte samples. Return a +tuple \code{(\var{offset}, \var{factor})} where \var{offset} is the (integer) offset into \var{fragment} where the optimal match started -and \var{factor} the floating-point factor as per \code{findfactor}. +and \var{factor} is the (floating-point) factor as per +\code{findfactor}. \end{funcdesc} \begin{funcdesc}{findmax}{fragment\, length} -This routine (which only accepts 2-byte sample fragments) searches -\var{fragment} for a slice of length \var{length} samples (not bytes!)\ -with maximum energy, i.e.\ it returns \var{i} for which -\code{rms(fragment[i*2:(i+length)*2])} is maximal. +Search \var{fragment} for a slice of length \var{length} samples (not +bytes!)\ with maximum energy, i.e., return \var{i} for which +\code{rms(fragment[i*2:(i+length)*2])} is maximal. The fragments +should both contain 2-byte samples. The routine takes time proportional to \code{len(fragment)}. \end{funcdesc} \begin{funcdesc}{getsample}{fragment\, width\, index} -This function returns the value of sample \var{index} from the -fragment. +Return the value of sample \var{index} from the fragment. \end{funcdesc} \begin{funcdesc}{lin2lin}{fragment\, width\, newwidth} -This function converts samples between 1-, 2- and 4-byte formats. +Convert samples between 1-, 2- and 4-byte formats. \end{funcdesc} \begin{funcdesc}{lin2adpcm}{fragment\, width\, state} -This function converts samples to 4 bit Intel/DVI ADPCM encoding. -ADPCM coding is an adaptive coding scheme, whereby each 4 bit number -is the difference between one sample and the next, divided by a -(varying) step. The Intel/DVI ADPCM algorithm has been selected for -use by the IMA, so it may well become a standard. +Convert samples to 4 bit Intel/DVI ADPCM encoding. ADPCM coding is an +adaptive coding scheme, whereby each 4 bit number is the difference +between one sample and the next, divided by a (varying) step. The +Intel/DVI ADPCM algorithm has been selected for use by the IMA, so it +may well become a standard. -\code{State} is a tuple containing the state of the coder. The coder +\code{State} is a tuple containing the state of the coder. The coder returns a tuple \code{(\var{adpcmfrag}, \var{newstate})}, and the \var{newstate} should be passed to the next call of lin2adpcm. In the -initial call \code{None} can be passed as the state. \var{adpcmfrag} is -the ADPCM coded fragment packed 2 4-bit values per byte. +initial call \code{None} can be passed as the state. \var{adpcmfrag} +is the ADPCM coded fragment packed 2 4-bit values per byte. \end{funcdesc} \begin{funcdesc}{lin2adpcm3}{fragment\, width\, state} This is an alternative ADPCM coder that uses only 3 bits per sample. It is not compatible with the Intel/DVI ADPCM coder and its output is -not packed (due to laziness on the side of the author). Its use is +not packed (due to laziness on the side of the author). Its use is discouraged. \end{funcdesc} \begin{funcdesc}{lin2ulaw}{fragment\, width} -This function converts samples in the audio fragment to U-LAW encoding -and returns this as a Python string. U-LAW is an audio encoding format -whereby you get a dynamic range of about 14 bits using only 8 bit -samples. It is used by the Sun audio hardware, among others. +Convert samples in the audio fragment to U-LAW encoding and return +this as a Python string. U-LAW is an audio encoding format whereby +you get a dynamic range of about 14 bits using only 8 bit samples. It +is used by the Sun audio hardware, among others. \end{funcdesc} \begin{funcdesc}{minmax}{fragment\, width} -This function returns a tuple consisting of the minimum and maximum -values of all samples in the sound fragment. +Return a tuple consisting of the minimum and maximum values of all +samples in the sound fragment. \end{funcdesc} \begin{funcdesc}{max}{fragment\, width} -This function returns the maximum of the {\em absolute value} of all -samples in a fragment. +Return the maximum of the {\em absolute value} of all samples in a +fragment. \end{funcdesc} \begin{funcdesc}{maxpp}{fragment\, width} -This function returns the maximum peak-peak value in the sound fragment. +Return the maximum peak-peak value in the sound fragment. \end{funcdesc} \begin{funcdesc}{mul}{fragment\, width\, factor} Return a fragment that has all samples in the original framgent -multiplied by the floating-point value \var{factor}. Overflow is +multiplied by the floating-point value \var{factor}. Overflow is silently ignored. \end{funcdesc} \begin{funcdesc}{reverse}{fragment\, width} -This function reverses the samples in a fragment and returns the -modified fragment. +Reverse the samples in a fragment and returns the modified fragment. \end{funcdesc} -\begin{funcdesc}{rms}{fragment\, width\, factor} -Returns the root-mean-square of the fragment, i.e. +\begin{funcdesc}{rms}{fragment\, width} +Return the root-mean-square of the fragment, i.e. \iftexi the square root of the quotient of the sum of all squared sample value, divided by the sumber of samples. @@ -166,22 +166,22 @@ This is a measure of the power in an audio signal. \end{funcdesc} \begin{funcdesc}{tomono}{fragment\, width\, lfactor\, rfactor} -This function converts a stereo fragment to a mono fragment. The left -channel is multiplied by \var{lfactor} and the right channel by -\var{rfactor} before adding the two channels to give a mono signal. +Convert a stereo fragment to a mono fragment. The left channel is +multiplied by \var{lfactor} and the right channel by \var{rfactor} +before adding the two channels to give a mono signal. \end{funcdesc} \begin{funcdesc}{tostereo}{fragment\, width\, lfactor\, rfactor} -This function generates a stereo fragment from a mono fragment. Each -pair of samples in the stereo fragment are computed from the mono -sample, whereby left channel samples are multiplied by \var{lfactor} -and right channel samples by \var{rfactor}. +Generate a stereo fragment from a mono fragment. Each pair of samples +in the stereo fragment are computed from the mono sample, whereby left +channel samples are multiplied by \var{lfactor} and right channel +samples by \var{rfactor}. \end{funcdesc} \begin{funcdesc}{ulaw2lin}{fragment\, width} -This function converts sound fragments in ULAW encoding to linearly -encoded sound fragments. ULAW encoding always uses 8 bits samples, so -\var{width} refers only to the sample width of the output fragment here. +Convert sound fragments in ULAW encoding to linearly encoded sound +fragments. ULAW encoding always uses 8 bits samples, so \var{width} +refers only to the sample width of the output fragment here. \end{funcdesc} Note that operations such as \code{mul} or \code{max} make no @@ -202,20 +202,20 @@ def mul_stereo(sample, width, lfactor, rfactor): 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 not only transmit the data but also the state. Note that you should send the \var{initial} state (the one you passed to \code{lin2adpcm}) along to the decoder, not the final state (as returned by -the coder). If you want to use \code{struct} to store the state in +the coder). If you want to use \code{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 +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 \code{find...} routines might look a bit funny at first sight. -They are primarily meant for doing echo cancellation. A reasonably +They are primarily meant to do 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: |