1998-08-10 16:42:37 -03:00
|
|
|
\section{\module{aifc} ---
|
|
|
|
Read and write audio files in AIFF or AIFC format.}
|
1998-07-23 14:59:49 -03:00
|
|
|
\declaremodule{standard}{aifc}
|
|
|
|
|
|
|
|
\modulesynopsis{Read and write audio files in AIFF or AIFC format.}
|
|
|
|
|
1994-09-29 13:46:42 -03:00
|
|
|
|
|
|
|
This module provides support for reading and writing AIFF and AIFF-C
|
|
|
|
files. AIFF is Audio Interchange File Format, a format for storing
|
|
|
|
digital audio samples in a file. AIFF-C is a newer version of the
|
|
|
|
format that includes the ability to compress the audio data.
|
1998-04-04 03:15:02 -04:00
|
|
|
\index{Audio Interchange File Format}
|
|
|
|
\index{AIFF}
|
|
|
|
\index{AIFF-C}
|
1994-09-29 13:46:42 -03:00
|
|
|
|
|
|
|
Audio files have a number of parameters that describe the audio data.
|
|
|
|
The sampling rate or frame rate is the number of times per second the
|
|
|
|
sound is sampled. The number of channels indicate if the audio is
|
|
|
|
mono, stereo, or quadro. Each frame consists of one sample per
|
|
|
|
channel. The sample size is the size in bytes of each sample. Thus a
|
1995-03-28 09:35:14 -04:00
|
|
|
frame consists of \var{nchannels}*\var{samplesize} bytes, and a
|
|
|
|
second's worth of audio consists of
|
|
|
|
\var{nchannels}*\var{samplesize}*\var{framerate} bytes.
|
|
|
|
|
|
|
|
For example, CD quality audio has a sample size of two bytes (16
|
|
|
|
bits), uses two channels (stereo) and has a frame rate of 44,100
|
|
|
|
frames/second. This gives a frame size of 4 bytes (2*2), and a
|
|
|
|
second's worth occupies 2*2*44100 bytes, i.e.\ 176,400 bytes.
|
1994-09-29 13:46:42 -03:00
|
|
|
|
1998-04-04 03:15:02 -04:00
|
|
|
Module \module{aifc} defines the following function:
|
1994-09-29 13:46:42 -03:00
|
|
|
|
1998-03-17 02:33:25 -04:00
|
|
|
\begin{funcdesc}{open}{file, mode}
|
1995-03-13 06:03:32 -04:00
|
|
|
Open an AIFF or AIFF-C file and return an object instance with
|
1994-09-29 13:46:42 -03:00
|
|
|
methods that are described below. The argument file is either a
|
|
|
|
string naming a file or a file object. The mode is either the string
|
1995-03-17 12:07:09 -04:00
|
|
|
\code{'r'} when the file must be opened for reading, or \code{'w'}
|
|
|
|
when the file must be opened for writing. When used for writing, the
|
|
|
|
file object should be seekable, unless you know ahead of time how many
|
|
|
|
samples you are going to write in total and use
|
1998-04-04 03:15:02 -04:00
|
|
|
\method{writeframesraw()} and \method{setnframes()}.
|
1994-09-29 13:46:42 -03:00
|
|
|
\end{funcdesc}
|
|
|
|
|
1998-04-04 03:15:02 -04:00
|
|
|
Objects returned by \function{open()} when a file is opened for
|
1994-09-29 13:46:42 -03:00
|
|
|
reading have the following methods:
|
|
|
|
|
1998-04-04 03:15:02 -04:00
|
|
|
\begin{methoddesc}[aifc]{getnchannels}{}
|
1994-09-29 13:46:42 -03:00
|
|
|
Return the number of audio channels (1 for mono, 2 for stereo).
|
1998-04-04 03:15:02 -04:00
|
|
|
\end{methoddesc}
|
1994-09-29 13:46:42 -03:00
|
|
|
|
1998-04-04 03:15:02 -04:00
|
|
|
\begin{methoddesc}[aifc]{getsampwidth}{}
|
1994-09-29 13:46:42 -03:00
|
|
|
Return the size in bytes of individual samples.
|
1998-04-04 03:15:02 -04:00
|
|
|
\end{methoddesc}
|
1994-09-29 13:46:42 -03:00
|
|
|
|
1998-04-04 03:15:02 -04:00
|
|
|
\begin{methoddesc}[aifc]{getframerate}{}
|
1994-09-29 13:46:42 -03:00
|
|
|
Return the sampling rate (number of audio frames per second).
|
1998-04-04 03:15:02 -04:00
|
|
|
\end{methoddesc}
|
1994-09-29 13:46:42 -03:00
|
|
|
|
1998-04-04 03:15:02 -04:00
|
|
|
\begin{methoddesc}[aifc]{getnframes}{}
|
1994-09-29 13:46:42 -03:00
|
|
|
Return the number of audio frames in the file.
|
1998-04-04 03:15:02 -04:00
|
|
|
\end{methoddesc}
|
1994-09-29 13:46:42 -03:00
|
|
|
|
1998-04-04 03:15:02 -04:00
|
|
|
\begin{methoddesc}[aifc]{getcomptype}{}
|
1994-09-29 13:46:42 -03:00
|
|
|
Return a four-character string describing the type of compression used
|
|
|
|
in the audio file. For AIFF files, the returned value is
|
|
|
|
\code{'NONE'}.
|
1998-04-04 03:15:02 -04:00
|
|
|
\end{methoddesc}
|
1994-09-29 13:46:42 -03:00
|
|
|
|
1998-04-04 03:15:02 -04:00
|
|
|
\begin{methoddesc}[aifc]{getcompname}{}
|
1994-09-29 13:46:42 -03:00
|
|
|
Return a human-readable description of the type of compression used in
|
|
|
|
the audio file. For AIFF files, the returned value is \code{'not
|
|
|
|
compressed'}.
|
1998-04-04 03:15:02 -04:00
|
|
|
\end{methoddesc}
|
1994-09-29 13:46:42 -03:00
|
|
|
|
1998-04-04 03:15:02 -04:00
|
|
|
\begin{methoddesc}[aifc]{getparams}{}
|
1994-09-29 13:46:42 -03:00
|
|
|
Return a tuple consisting of all of the above values in the above
|
|
|
|
order.
|
1998-04-04 03:15:02 -04:00
|
|
|
\end{methoddesc}
|
1994-09-29 13:46:42 -03:00
|
|
|
|
1998-04-04 03:15:02 -04:00
|
|
|
\begin{methoddesc}[aifc]{getmarkers}{}
|
1994-09-29 13:46:42 -03:00
|
|
|
Return a list of markers in the audio file. A marker consists of a
|
|
|
|
tuple of three elements. The first is the mark ID (an integer), the
|
|
|
|
second is the mark position in frames from the beginning of the data
|
|
|
|
(an integer), the third is the name of the mark (a string).
|
1998-04-04 03:15:02 -04:00
|
|
|
\end{methoddesc}
|
1994-09-29 13:46:42 -03:00
|
|
|
|
1998-04-04 03:15:02 -04:00
|
|
|
\begin{methoddesc}[aifc]{getmark}{id}
|
|
|
|
Return the tuple as described in \method{getmarkers()} for the mark
|
|
|
|
with the given \var{id}.
|
|
|
|
\end{methoddesc}
|
1994-09-29 13:46:42 -03:00
|
|
|
|
1998-04-04 03:15:02 -04:00
|
|
|
\begin{methoddesc}[aifc]{readframes}{nframes}
|
1995-03-13 06:03:32 -04:00
|
|
|
Read and return the next \var{nframes} frames from the audio file. The
|
1994-09-29 13:46:42 -03:00
|
|
|
returned data is a string containing for each frame the uncompressed
|
|
|
|
samples of all channels.
|
1998-04-04 03:15:02 -04:00
|
|
|
\end{methoddesc}
|
1994-09-29 13:46:42 -03:00
|
|
|
|
1998-04-04 03:15:02 -04:00
|
|
|
\begin{methoddesc}[aifc]{rewind}{}
|
|
|
|
Rewind the read pointer. The next \method{readframes()} will start from
|
1994-09-29 13:46:42 -03:00
|
|
|
the beginning.
|
1998-04-04 03:15:02 -04:00
|
|
|
\end{methoddesc}
|
1994-09-29 13:46:42 -03:00
|
|
|
|
1998-04-04 03:15:02 -04:00
|
|
|
\begin{methoddesc}[aifc]{setpos}{pos}
|
1994-09-29 13:46:42 -03:00
|
|
|
Seek to the specified frame number.
|
1998-04-04 03:15:02 -04:00
|
|
|
\end{methoddesc}
|
1994-09-29 13:46:42 -03:00
|
|
|
|
1998-04-04 03:15:02 -04:00
|
|
|
\begin{methoddesc}[aifc]{tell}{}
|
1994-09-29 13:46:42 -03:00
|
|
|
Return the current frame number.
|
1998-04-04 03:15:02 -04:00
|
|
|
\end{methoddesc}
|
1994-09-29 13:46:42 -03:00
|
|
|
|
1998-04-04 03:15:02 -04:00
|
|
|
\begin{methoddesc}[aifc]{close}{}
|
1994-09-29 13:46:42 -03:00
|
|
|
Close the AIFF file. After calling this method, the object can no
|
|
|
|
longer be used.
|
1998-04-04 03:15:02 -04:00
|
|
|
\end{methoddesc}
|
1994-09-29 13:46:42 -03:00
|
|
|
|
1998-04-04 03:15:02 -04:00
|
|
|
Objects returned by \function{open()} when a file is opened for
|
|
|
|
writing have all the above methods, except for \method{readframes()} and
|
|
|
|
\method{setpos()}. In addition the following methods exist. The
|
|
|
|
\method{get*()} methods can only be called after the corresponding
|
|
|
|
\method{set*()} methods have been called. Before the first
|
|
|
|
\method{writeframes()} or \method{writeframesraw()}, all parameters
|
|
|
|
except for the number of frames must be filled in.
|
1994-09-29 13:46:42 -03:00
|
|
|
|
1998-04-04 03:15:02 -04:00
|
|
|
\begin{methoddesc}[aifc]{aiff}{}
|
1994-09-29 13:46:42 -03:00
|
|
|
Create an AIFF file. The default is that an AIFF-C file is created,
|
1998-02-13 18:22:36 -04:00
|
|
|
unless the name of the file ends in \code{'.aiff'} in which case the
|
|
|
|
default is an AIFF file.
|
1998-04-04 03:15:02 -04:00
|
|
|
\end{methoddesc}
|
1994-09-29 13:46:42 -03:00
|
|
|
|
1998-04-04 03:15:02 -04:00
|
|
|
\begin{methoddesc}[aifc]{aifc}{}
|
1994-09-29 13:46:42 -03:00
|
|
|
Create an AIFF-C file. The default is that an AIFF-C file is created,
|
1998-02-13 18:22:36 -04:00
|
|
|
unless the name of the file ends in \code{'.aiff'} in which case the
|
|
|
|
default is an AIFF file.
|
1998-04-04 03:15:02 -04:00
|
|
|
\end{methoddesc}
|
1994-09-29 13:46:42 -03:00
|
|
|
|
1998-04-04 03:15:02 -04:00
|
|
|
\begin{methoddesc}[aifc]{setnchannels}{nchannels}
|
1994-09-29 13:46:42 -03:00
|
|
|
Specify the number of channels in the audio file.
|
1998-04-04 03:15:02 -04:00
|
|
|
\end{methoddesc}
|
1994-09-29 13:46:42 -03:00
|
|
|
|
1998-04-04 03:15:02 -04:00
|
|
|
\begin{methoddesc}[aifc]{setsampwidth}{width}
|
1994-09-29 13:46:42 -03:00
|
|
|
Specify the size in bytes of audio samples.
|
1998-04-04 03:15:02 -04:00
|
|
|
\end{methoddesc}
|
1994-09-29 13:46:42 -03:00
|
|
|
|
1998-04-04 03:15:02 -04:00
|
|
|
\begin{methoddesc}[aifc]{setframerate}{rate}
|
1994-09-29 13:46:42 -03:00
|
|
|
Specify the sampling frequency in frames per second.
|
1998-04-04 03:15:02 -04:00
|
|
|
\end{methoddesc}
|
1994-09-29 13:46:42 -03:00
|
|
|
|
1998-04-04 03:15:02 -04:00
|
|
|
\begin{methoddesc}[aifc]{setnframes}{nframes}
|
1994-09-29 13:46:42 -03:00
|
|
|
Specify the number of frames that are to be written to the audio file.
|
|
|
|
If this parameter is not set, or not set correctly, the file needs to
|
|
|
|
support seeking.
|
1998-04-04 03:15:02 -04:00
|
|
|
\end{methoddesc}
|
1994-09-29 13:46:42 -03:00
|
|
|
|
1998-04-04 03:15:02 -04:00
|
|
|
\begin{methoddesc}[aifc]{setcomptype}{type, name}
|
1994-09-29 13:46:42 -03:00
|
|
|
Specify the compression type. If not specified, the audio data will
|
|
|
|
not be compressed. In AIFF files, compression is not possible. The
|
|
|
|
name parameter should be a human-readable description of the
|
|
|
|
compression type, the type parameter should be a four-character
|
|
|
|
string. Currently the following compression types are supported:
|
|
|
|
NONE, ULAW, ALAW, G722.
|
1998-04-04 03:15:02 -04:00
|
|
|
\index{u-LAW}
|
|
|
|
\index{A-LAW}
|
|
|
|
\index{G.722}
|
|
|
|
\end{methoddesc}
|
1994-09-29 13:46:42 -03:00
|
|
|
|
1998-04-04 03:15:02 -04:00
|
|
|
\begin{methoddesc}[aifc]{setparams}{nchannels, sampwidth, framerate, comptype, compname}
|
1994-09-29 13:46:42 -03:00
|
|
|
Set all the above parameters at once. The argument is a tuple
|
|
|
|
consisting of the various parameters. This means that it is possible
|
1998-04-04 03:15:02 -04:00
|
|
|
to use the result of a \method{getparams()} call as argument to
|
|
|
|
\method{setparams()}.
|
|
|
|
\end{methoddesc}
|
1994-09-29 13:46:42 -03:00
|
|
|
|
1998-04-04 03:15:02 -04:00
|
|
|
\begin{methoddesc}[aifc]{setmark}{id, pos, name}
|
1994-09-29 13:46:42 -03:00
|
|
|
Add a mark with the given id (larger than 0), and the given name at
|
|
|
|
the given position. This method can be called at any time before
|
1998-04-04 03:15:02 -04:00
|
|
|
\method{close()}.
|
|
|
|
\end{methoddesc}
|
1994-09-29 13:46:42 -03:00
|
|
|
|
1998-04-04 03:15:02 -04:00
|
|
|
\begin{methoddesc}[aifc]{tell}{}
|
1994-09-29 13:46:42 -03:00
|
|
|
Return the current write position in the output file. Useful in
|
1998-04-04 03:15:02 -04:00
|
|
|
combination with \method{setmark()}.
|
|
|
|
\end{methoddesc}
|
1994-09-29 13:46:42 -03:00
|
|
|
|
1998-04-04 03:15:02 -04:00
|
|
|
\begin{methoddesc}[aifc]{writeframes}{data}
|
1994-09-29 13:46:42 -03:00
|
|
|
Write data to the output file. This method can only be called after
|
|
|
|
the audio file parameters have been set.
|
1998-04-04 03:15:02 -04:00
|
|
|
\end{methoddesc}
|
1994-09-29 13:46:42 -03:00
|
|
|
|
1998-04-04 03:15:02 -04:00
|
|
|
\begin{methoddesc}[aifc]{writeframesraw}{data}
|
|
|
|
Like \method{writeframes()}, except that the header of the audio file
|
|
|
|
is not updated.
|
|
|
|
\end{methoddesc}
|
1994-09-29 13:46:42 -03:00
|
|
|
|
1998-04-04 03:15:02 -04:00
|
|
|
\begin{methoddesc}[aifc]{close}{}
|
1994-09-29 13:46:42 -03:00
|
|
|
Close the AIFF file. The header of the file is updated to reflect the
|
1995-03-13 06:03:32 -04:00
|
|
|
actual size of the audio data. After calling this method, the object
|
1994-09-29 13:46:42 -03:00
|
|
|
can no longer be used.
|
1998-04-04 03:15:02 -04:00
|
|
|
\end{methoddesc}
|