blob: 3850ce9cb1cc92134db0419eb4bd276efec6f6e5 [file] [log] [blame]
Fred Drakeb742a421999-06-23 13:33:40 +00001\section{\module{sunau} ---
2 Read and write Sun AU files}
3
4\declaremodule{standard}{sunau}
5\sectionauthor{Moshe Zadka}{mzadka@geocities.com}
6\modulesynopsis{Provide an interface to the Sun AU sound format.}
7
8The \module{sunau} module provides a convenient interface to the Sun AU sound
9format. Note that this module is interface-compatible with the modules
10\refmodule{aifc} and \refmodule{wave}.
11
12The \module{sunau} module defines the following functions:
13
14\begin{funcdesc}{open}{file, mode}
15If \var{file} is a string, open the file by that name, otherwise treat it
16as a seekable file-like object. \var{mode} can be any of
17\begin{description}
18 \item[\code{'r'}] Read only mode.
19 \item[\code{'w'}] Write only mode.
20\end{description}
21Note that it does not allow read/write files.
22
23A \var{mode} of \code{'r'} returns a \class{AU_read}
24object, while a \var{mode} of \code{'w'} or \code{'wb'} returns
25a \class{AU_write} object.
26\end{funcdesc}
27
28\begin{funcdesc}{openfp}{file, mode}
29A synonym for \function{open}, maintained for backwards compatibility.
30\end{funcdesc}
31
32The \module{sunau} module defines the following exception:
33
34\begin{excdesc}{Error}
35An error raised when something is impossible because of Sun AU specs or
36implementation deficiency.
37\end{excdesc}
38
39The \module{sunau} module defines the following data item:
40
41\begin{datadesc}{AUDIO_FILE_MAGIC}
42An integer every valid Sun AU file begins with a big-endian encoding of.
43\end{datadesc}
44
45
46\subsection{AU_read Objects \label{au-read-objects}}
47
48AU_read objects, as returned by \function{open()} above, have the
49following methods:
50
51\begin{methoddesc}[AU_read]{close}{}
52Close the stream, and make the instance unusable. (This is
53called automatically on deletion.)
54\end{methoddesc}
55
56\begin{methoddesc}[AU_read]{getnchannels}{}
57Returns number of audio channels (1 for mone, 2 for stereo).
58\end{methoddesc}
59
60\begin{methoddesc}[AU_read]{getsampwidth}{}
61Returns sample width in bytes.
62\end{methoddesc}
63
64\begin{methoddesc}[AU_read]{getframerate}{}
65Returns sampling frequency.
66\end{methoddesc}
67
68\begin{methoddesc}[AU_read]{getnframes}{}
69Returns number of audio frames.
70\end{methoddesc}
71
72\begin{methoddesc}[AU_read]{getcomptype}{}
73Returns compression type.
74Supported compression types are \code{'ULAW'}, \code{'ALAW'} and \code{'NONE'}.
75\end{methoddesc}
76
77\begin{methoddesc}[AU_read]{getcompname}{}
78Human-readable version of \method{getcomptype()}.
79The supported types have the respective names \code{'CCITT G.711
80u-law'}, \code{'CCITT G.711 A-law'} and \code{'not compressed'}.
81\end{methoddesc}
82
83\begin{methoddesc}[AU_read]{getparams}{}
84Returns a tuple \code{(\var{nchannels}, \var{sampwidth},
85\var{framerate}, \var{nframes}, \var{comptype}, \var{compname})},
86equivalent to output of the \method{get*()} methods.
87\end{methoddesc}
88
89\begin{methoddesc}[AU_read]{readframes}{n}
90Reads and returns at most \var{n} frames of audio, as a string of bytes.
91\end{methoddesc}
92
93\begin{methoddesc}[AU_read]{rewind}{}
94Rewind the file pointer to the beginning of the audio stream.
95\end{methoddesc}
96
97The following two methods define a term ``position'' which is compatible
98between them, and is otherwise implementation dependant.
99
100\begin{methoddesc}[AU_read]{setpos}{pos}
101Set the file pointer to the specified position.
102\end{methoddesc}
103
104\begin{methoddesc}[AU_read]{tell}{}
105Return current file pointer position.
106\end{methoddesc}
107
108The following two functions are defined for compatibility with the
109\refmodule{aifc}, and don't do anything interesting.
110
111\begin{methoddesc}[AU_read]{getmarkers}{}
112Returns \code{None}.
113\end{methoddesc}
114
115\begin{methoddesc}[AU_read]{getmark}{id}
116Raise an error.
117\end{methoddesc}
118
119
120\subsection{AU_write Objects \label{au-write-objects}}
121
122AU_write objects, as returned by \function{open()} above, have the
123following methods:
124
125\begin{methoddesc}[AU_write]{setnchannels}{n}
126Set the number of channels.
127\end{methoddesc}
128
129\begin{methoddesc}[AU_write]{setsampwidth}{n}
130Set the sample width (in bytes.)
131\end{methoddesc}
132
133\begin{methoddesc}[AU_write]{setframerate}{n}
134Set the frame rate.
135\end{methoddesc}
136
137\begin{methoddesc}[AU_write]{setnframes}{n}
138Set the number of frames. This can be later changed, when and if more
139frames are written.
140\end{methoddesc}
141
142
143\begin{methoddesc}[AU_write]{setcomptype}{type, name}
144Set the compression type and description.
145Only \code{'NONE'} and \code{'ULAW'} are supported on output.
146\end{methoddesc}
147
148\begin{methoddesc}[AU_write]{setparams}{tuple}
149The \var{tuple} should be \code{(\var{nchannels}, \var{sampwidth},
150\var{framerate}, \var{nframes}, \var{comptype}, \var{compname})}, with
151values valid for the \method{set*()} methods. Set all parameters.
152\end{methoddesc}
153
154\begin{methoddesc}[AU_write]{tell}{}
155Return current position in the file, with the same disclaimer for
156the \method{AU_read.tell()} and \method{AU_read.setpos()} methods.
157\end{methoddesc}
158
159\begin{methoddesc}[AU_write]{writeframesraw}{data}
160Write audio frames, without correcting \var{nframes}.
161\end{methoddesc}
162
163\begin{methoddesc}[AU_write]{writeframes}{data}
164Write audio frames and make sure \var{nframes} is correct.
165\end{methoddesc}
166
167\begin{methoddesc}[AU_write]{close}{}
168Make sure \var{nframes} is correct, and close the file.
169
170This method is called upon deletion.
171\end{methoddesc}
172
173Note that it is invalid to set any parameters after calling
174\method{writeframes()} or \method{writeframesraw()}.