| 1 | \section{\module{aifc} ---
|
|---|
| 2 | Read and write AIFF and AIFC files}
|
|---|
| 3 |
|
|---|
| 4 | \declaremodule{standard}{aifc}
|
|---|
| 5 | \modulesynopsis{Read and write audio files in AIFF or AIFC format.}
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 | This module provides support for reading and writing AIFF and AIFF-C
|
|---|
| 9 | files. AIFF is Audio Interchange File Format, a format for storing
|
|---|
| 10 | digital audio samples in a file. AIFF-C is a newer version of the
|
|---|
| 11 | format that includes the ability to compress the audio data.
|
|---|
| 12 | \index{Audio Interchange File Format}
|
|---|
| 13 | \index{AIFF}
|
|---|
| 14 | \index{AIFF-C}
|
|---|
| 15 |
|
|---|
| 16 | \strong{Caveat:} Some operations may only work under IRIX; these will
|
|---|
| 17 | raise \exception{ImportError} when attempting to import the
|
|---|
| 18 | \module{cl} module, which is only available on IRIX.
|
|---|
| 19 |
|
|---|
| 20 | Audio files have a number of parameters that describe the audio data.
|
|---|
| 21 | The sampling rate or frame rate is the number of times per second the
|
|---|
| 22 | sound is sampled. The number of channels indicate if the audio is
|
|---|
| 23 | mono, stereo, or quadro. Each frame consists of one sample per
|
|---|
| 24 | channel. The sample size is the size in bytes of each sample. Thus a
|
|---|
| 25 | frame consists of \var{nchannels}*\var{samplesize} bytes, and a
|
|---|
| 26 | second's worth of audio consists of
|
|---|
| 27 | \var{nchannels}*\var{samplesize}*\var{framerate} bytes.
|
|---|
| 28 |
|
|---|
| 29 | For example, CD quality audio has a sample size of two bytes (16
|
|---|
| 30 | bits), uses two channels (stereo) and has a frame rate of 44,100
|
|---|
| 31 | frames/second. This gives a frame size of 4 bytes (2*2), and a
|
|---|
| 32 | second's worth occupies 2*2*44100 bytes (176,400 bytes).
|
|---|
| 33 |
|
|---|
| 34 | Module \module{aifc} defines the following function:
|
|---|
| 35 |
|
|---|
| 36 | \begin{funcdesc}{open}{file\optional{, mode}}
|
|---|
| 37 | Open an AIFF or AIFF-C file and return an object instance with
|
|---|
| 38 | methods that are described below. The argument \var{file} is either a
|
|---|
| 39 | string naming a file or a file object. \var{mode} must be \code{'r'}
|
|---|
| 40 | or \code{'rb'} when the file must be opened for reading, or \code{'w'}
|
|---|
| 41 | or \code{'wb'} when the file must be opened for writing. If omitted,
|
|---|
| 42 | \code{\var{file}.mode} is used if it exists, otherwise \code{'rb'} is
|
|---|
| 43 | used. When used for writing, the file object should be seekable,
|
|---|
| 44 | unless you know ahead of time how many samples you are going to write
|
|---|
| 45 | in total and use \method{writeframesraw()} and \method{setnframes()}.
|
|---|
| 46 | \end{funcdesc}
|
|---|
| 47 |
|
|---|
| 48 | Objects returned by \function{open()} when a file is opened for
|
|---|
| 49 | reading have the following methods:
|
|---|
| 50 |
|
|---|
| 51 | \begin{methoddesc}[aifc]{getnchannels}{}
|
|---|
| 52 | Return the number of audio channels (1 for mono, 2 for stereo).
|
|---|
| 53 | \end{methoddesc}
|
|---|
| 54 |
|
|---|
| 55 | \begin{methoddesc}[aifc]{getsampwidth}{}
|
|---|
| 56 | Return the size in bytes of individual samples.
|
|---|
| 57 | \end{methoddesc}
|
|---|
| 58 |
|
|---|
| 59 | \begin{methoddesc}[aifc]{getframerate}{}
|
|---|
| 60 | Return the sampling rate (number of audio frames per second).
|
|---|
| 61 | \end{methoddesc}
|
|---|
| 62 |
|
|---|
| 63 | \begin{methoddesc}[aifc]{getnframes}{}
|
|---|
| 64 | Return the number of audio frames in the file.
|
|---|
| 65 | \end{methoddesc}
|
|---|
| 66 |
|
|---|
| 67 | \begin{methoddesc}[aifc]{getcomptype}{}
|
|---|
| 68 | Return a four-character string describing the type of compression used
|
|---|
| 69 | in the audio file. For AIFF files, the returned value is
|
|---|
| 70 | \code{'NONE'}.
|
|---|
| 71 | \end{methoddesc}
|
|---|
| 72 |
|
|---|
| 73 | \begin{methoddesc}[aifc]{getcompname}{}
|
|---|
| 74 | Return a human-readable description of the type of compression used in
|
|---|
| 75 | the audio file. For AIFF files, the returned value is \code{'not
|
|---|
| 76 | compressed'}.
|
|---|
| 77 | \end{methoddesc}
|
|---|
| 78 |
|
|---|
| 79 | \begin{methoddesc}[aifc]{getparams}{}
|
|---|
| 80 | Return a tuple consisting of all of the above values in the above
|
|---|
| 81 | order.
|
|---|
|
|---|