Commit f2a87466 authored by Anthony Baxter's avatar Anthony Baxter

SF [ 1231053 ] audioop - alaw encoding/decoding added, code updated

 This patch adds a-LAW encoding to audioop and replaces the old
u-LAW encoding/decoding code with the current code from sox.

Possible issues: the code from sox uses int16_t.

Code by Lars Immisch
parent 2c614203
......@@ -12,9 +12,10 @@ is the same format as used by the \refmodule{al} and \refmodule{sunaudiodev}
modules. All scalar items are integers, unless specified otherwise.
% This para is mostly here to provide an excuse for the index entries...
This module provides support for u-LAW and Intel/DVI ADPCM encodings.
This module provides support for a-LAW, u-LAW and Intel/DVI ADPCM encodings.
\index{Intel/DVI ADPCM}
\index{ADPCM, Intel/DVI}
\index{a-LAW}
\index{u-LAW}
A few of the more complicated operations only take 16-bit samples,
......@@ -42,6 +43,13 @@ Return a tuple \code{(\var{sample}, \var{newstate})} where the sample
has the width specified in \var{width}.
\end{funcdesc}
\begin{funcdesc}{alaw2lin}{fragment, width}
Convert sound fragments in a-LAW encoding to linearly encoded sound
fragments. a-LAW encoding always uses 8 bits samples, so \var{width}
refers only to the sample width of the output fragment here.
\versionadded{2.5}
\end{funcdesc}
\begin{funcdesc}{avg}{fragment, width}
Return the average over all samples in the fragment.
\end{funcdesc}
......@@ -98,10 +106,6 @@ The routine takes time proportional to \code{len(\var{fragment})}.
Return the value of sample \var{index} from the fragment.
\end{funcdesc}
\begin{funcdesc}{lin2lin}{fragment, width, newwidth}
Convert samples between 1-, 2- and 4-byte formats.
\end{funcdesc}
\begin{funcdesc}{lin2adpcm}{fragment, width, state}
Convert samples to 4 bit Intel/DVI ADPCM encoding. ADPCM coding is an
adaptive coding scheme, whereby each 4 bit number is the difference
......@@ -117,6 +121,18 @@ passed as the state. \var{adpcmfrag} is the ADPCM coded fragment
packed 2 4-bit values per byte.
\end{funcdesc}
\begin{funcdesc}{lin2alaw}{fragment, width}
Convert samples in the audio fragment to a-LAW encoding and return
this as a Python string. a-LAW is an audio encoding format whereby
you get a dynamic range of about 13 bits using only 8 bit samples. It
is used by the Sun audio hardware, among others.
\versionadded{2.5}
\end{funcdesc}
\begin{funcdesc}{lin2lin}{fragment, width, newwidth}
Convert samples between 1-, 2- and 4-byte formats.
\end{funcdesc}
\begin{funcdesc}{lin2ulaw}{fragment, width}
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
......
......@@ -136,12 +136,30 @@ def testlin2adpcm(data):
return 0
return 1
def testlin2alaw(data):
if verbose:
print 'lin2alaw'
if audioop.lin2alaw(data[0], 1) != '\xd5\xc5\xf5' or \
audioop.lin2alaw(data[1], 2) != '\xd5\xd5\xd5' or \
audioop.lin2alaw(data[2], 4) != '\xd5\xd5\xd5':
return 0
return 1
def testalaw2lin(data):
if verbose:
print 'alaw2lin'
# Cursory
d = audioop.lin2alaw(data[0], 1)
if audioop.alaw2lin(d, 1) != data[0]:
return 0
return 1
def testlin2ulaw(data):
if verbose:
print 'lin2ulaw'
if audioop.lin2ulaw(data[0], 1) != '\377\347\333' or \
audioop.lin2ulaw(data[1], 2) != '\377\377\377' or \
audioop.lin2ulaw(data[2], 4) != '\377\377\377':
if audioop.lin2ulaw(data[0], 1) != '\xff\xe7\xdb' or \
audioop.lin2ulaw(data[1], 2) != '\xff\xff\xff' or \
audioop.lin2ulaw(data[2], 4) != '\xff\xff\xff':
return 0
return 1
......
......@@ -295,6 +295,9 @@ Core and builtins
Extension Modules
-----------------
- Patch #1231053: The audioop module now supports encoding/decoding of alaw.
In addition, the existing ulaw code was updated.
- RFE #567972: Socket objects' family, type and proto properties are
now exposed via new get...() methods.
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment