1 \section{\module{sunau
} ---
2 Read and write Sun AU files
}
4 \declaremodule{standard
}{sunau
}
5 \sectionauthor{Moshe Zadka
}{moshez@zadka.site.co.il
}
6 \modulesynopsis{Provide an interface to the Sun AU sound format.
}
8 The
\module{sunau
} module provides a convenient interface to the Sun
9 AU sound format. Note that this module is interface-compatible with
10 the modules
\refmodule{aifc
} and
\refmodule{wave
}.
12 An audio file consists of a header followed by the data. The fields
15 \begin{tableii
}{l|l
}{textrm
}{Field
}{Contents
}
16 \lineii{magic word
}{The four bytes
\samp{.snd
}.
}
17 \lineii{header size
}{Size of the header, including info, in bytes.
}
18 \lineii{data size
}{Physical size of the data, in bytes.
}
19 \lineii{encoding
}{Indicates how the audio samples are encoded.
}
20 \lineii{sample rate
}{The sampling rate.
}
21 \lineii{\# of channels
}{The number of channels in the samples.
}
22 \lineii{info
}{\ASCII{} string giving a description of the audio
23 file (padded with null bytes).
}
26 Apart from the info field, all header fields are
4 bytes in size.
27 They are all
32-bit unsigned integers encoded in big-endian byte
31 The
\module{sunau
} module defines the following functions:
33 \begin{funcdesc
}{open
}{file, mode
}
34 If
\var{file
} is a string, open the file by that name, otherwise treat it
35 as a seekable file-like object.
\var{mode
} can be any of
37 \item[\code{'r'
}] Read only mode.
38 \item[\code{'w'
}] Write only mode.
40 Note that it does not allow read/write files.
42 A
\var{mode
} of
\code{'r'
} returns a
\class{AU_read
}
43 object, while a
\var{mode
} of
\code{'w'
} or
\code{'wb'
} returns
44 a
\class{AU_write
} object.
47 \begin{funcdesc
}{openfp
}{file, mode
}
48 A synonym for
\function{open
}, maintained for backwards compatibility.
51 The
\module{sunau
} module defines the following exception:
53 \begin{excdesc
}{Error
}
54 An error raised when something is impossible because of Sun AU specs or
55 implementation deficiency.
58 The
\module{sunau
} module defines the following data items:
60 \begin{datadesc
}{AUDIO_FILE_MAGIC
}
61 An integer every valid Sun AU file begins with, stored in big-endian
62 form. This is the string
\samp{.snd
} interpreted as an integer.
65 \begin{datadesc
}{AUDIO_FILE_ENCODING_MULAW_8
}
66 \dataline{AUDIO_FILE_ENCODING_LINEAR_8
}
67 \dataline{AUDIO_FILE_ENCODING_LINEAR_16
}
68 \dataline{AUDIO_FILE_ENCODING_LINEAR_24
}
69 \dataline{AUDIO_FILE_ENCODING_LINEAR_32
}
70 \dataline{AUDIO_FILE_ENCODING_ALAW_8
}
71 Values of the encoding field from the AU header which are supported by
75 \begin{datadesc
}{AUDIO_FILE_ENCODING_FLOAT
}
76 \dataline{AUDIO_FILE_ENCODING_DOUBLE
}
77 \dataline{AUDIO_FILE_ENCODING_ADPCM_G721
}
78 \dataline{AUDIO_FILE_ENCODING_ADPCM_G722
}
79 \dataline{AUDIO_FILE_ENCODING_ADPCM_G723_3
}
80 \dataline{AUDIO_FILE_ENCODING_ADPCM_G723_5
}
81 Additional known values of the encoding field from the AU header, but
82 which are not supported by this module.
86 \subsection{AU_read Objects
\label{au-read-objects
}}
88 AU_read objects, as returned by
\function{open()
} above, have the
91 \begin{methoddesc
}[AU_read
]{close
}{}
92 Close the stream, and make the instance unusable. (This is
93 called automatically on deletion.)
96 \begin{methoddesc
}[AU_read
]{getnchannels
}{}
97 Returns number of audio channels (
1 for mone,
2 for stereo).
100 \begin{methoddesc
}[AU_read
]{getsampwidth
}{}
101 Returns sample width in bytes.
104 \begin{methoddesc
}[AU_read
]{getframerate
}{}
105 Returns sampling frequency.
108 \begin{methoddesc
}[AU_read
]{getnframes
}{}
109 Returns number of audio frames.
112 \begin{methoddesc
}[AU_read
]{getcomptype
}{}
113 Returns compression type.
114 Supported compression types are
\code{'ULAW'
},
\code{'ALAW'
} and
\code{'NONE'
}.
117 \begin{methoddesc
}[AU_read
]{getcompname
}{}
118 Human-readable version of
\method{getcomptype()
}.
119 The supported types have the respective names
\code{'CCITT G
.711
120 u-law'
},
\code{'CCITT G
.711 A-law'
} and
\code{'not compressed'
}.
123 \begin{methoddesc
}[AU_read
]{getparams
}{}
124 Returns a tuple
\code{(
\var{nchannels
},
\var{sampwidth
},
125 \var{framerate
},
\var{nframes
},
\var{comptype
},
\var{compname
})
},
126 equivalent to output of the
\method{get*()
} methods.
129 \begin{methoddesc
}[AU_read
]{readframes
}{n
}
130 Reads and returns at most
\var{n
} frames of audio, as a string of
131 bytes. The data will be returned in linear format. If the original
132 data is in u-LAW format, it will be converted.
135 \begin{methoddesc
}[AU_read
]{rewind
}{}
136 Rewind the file pointer to the beginning of the audio stream.
139 The following two methods define a term ``position'' which is compatible
140 between them, and is otherwise implementation dependent.
142 \begin{methoddesc
}[AU_read
]{setpos
}{pos
}
143 Set the file pointer to the specified position. Only values returned
144 from
\method{tell()
} should be used for
\var{pos
}.
147 \begin{methoddesc
}[AU_read
]{tell
}{}
148 Return current file pointer position. Note that the returned value
149 has nothing to do with the actual position in the file.
152 The following two functions are defined for compatibility with the
153 \refmodule{aifc
}, and don't do anything interesting.
155 \begin{methoddesc
}[AU_read
]{getmarkers
}{}
159 \begin{methoddesc
}[AU_read
]{getmark
}{id
}
164 \subsection{AU_write Objects
\label{au-write-objects
}}
166 AU_write objects, as returned by
\function{open()
} above, have the
169 \begin{methoddesc
}[AU_write
]{setnchannels
}{n
}
170 Set the number of channels.
173 \begin{methoddesc
}[AU_write
]{setsampwidth
}{n
}
174 Set the sample width (in bytes.)
177 \begin{methoddesc
}[AU_write
]{setframerate
}{n
}
181 \begin{methoddesc
}[AU_write
]{setnframes
}{n
}
182 Set the number of frames. This can be later changed, when and if more
187 \begin{methoddesc
}[AU_write
]{setcomptype
}{type, name
}
188 Set the compression type and description.
189 Only
\code{'NONE'
} and
\code{'ULAW'
} are supported on output.
192 \begin{methoddesc
}[AU_write
]{setparams
}{tuple
}
193 The
\var{tuple
} should be
\code{(
\var{nchannels
},
\var{sampwidth
},
194 \var{framerate
},
\var{nframes
},
\var{comptype
},
\var{compname
})
}, with
195 values valid for the
\method{set*()
} methods. Set all parameters.
198 \begin{methoddesc
}[AU_write
]{tell
}{}
199 Return current position in the file, with the same disclaimer for
200 the
\method{AU_read.tell()
} and
\method{AU_read.setpos()
} methods.
203 \begin{methoddesc
}[AU_write
]{writeframesraw
}{data
}
204 Write audio frames, without correcting
\var{nframes
}.
207 \begin{methoddesc
}[AU_write
]{writeframes
}{data
}
208 Write audio frames and make sure
\var{nframes
} is correct.
211 \begin{methoddesc
}[AU_write
]{close
}{}
212 Make sure
\var{nframes
} is correct, and close the file.
214 This method is called upon deletion.
217 Note that it is invalid to set any parameters after calling
218 \method{writeframes()
} or
\method{writeframesraw()
}.