| 
									
										
										
										
											1998-08-10 19:42:37 +00:00
										 |  |  | \section{\module{aifc} --- | 
					
						
							| 
									
										
										
										
											1999-02-20 04:51:16 +00:00
										 |  |  |          Read and write AIFF and AIFC files} | 
					
						
							| 
									
										
										
										
											1998-07-23 17:59:49 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1999-02-20 04:51:16 +00:00
										 |  |  | \declaremodule{standard}{aifc} | 
					
						
							| 
									
										
										
										
											1998-07-23 17:59:49 +00:00
										 |  |  | \modulesynopsis{Read and write audio files in AIFF or AIFC format.} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1994-09-29 16:46:42 +00: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 07:15:02 +00:00
										 |  |  | \index{Audio Interchange File Format} | 
					
						
							|  |  |  | \index{AIFF} | 
					
						
							|  |  |  | \index{AIFF-C} | 
					
						
							| 
									
										
										
										
											1994-09-29 16:46:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1999-01-20 16:26:09 +00:00
										 |  |  | \strong{Caveat:}  Some operations may only work under IRIX; these will | 
					
						
							|  |  |  | raise \exception{ImportError} when attempting to import the | 
					
						
							|  |  |  | \module{cl} module, which is only available on IRIX. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1994-09-29 16:46:42 +00: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 13:35:14 +00: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 | 
					
						
							| 
									
										
										
										
											2001-07-06 19:28:48 +00:00
										 |  |  | second's worth occupies 2*2*44100 bytes (176,400 bytes). | 
					
						
							| 
									
										
										
										
											1994-09-29 16:46:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1998-04-04 07:15:02 +00:00
										 |  |  | Module \module{aifc} defines the following function: | 
					
						
							| 
									
										
										
										
											1994-09-29 16:46:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1999-12-21 18:31:30 +00:00
										 |  |  | \begin{funcdesc}{open}{file\optional{, mode}} | 
					
						
							| 
									
										
										
										
											1995-03-13 10:03:32 +00:00
										 |  |  | Open an AIFF or AIFF-C file and return an object instance with | 
					
						
							| 
									
										
										
										
											1999-12-21 18:31:30 +00:00
										 |  |  | methods that are described below.  The argument \var{file} is either a | 
					
						
							|  |  |  | string naming a file or a file object.  \var{mode} must be \code{'r'} | 
					
						
							|  |  |  | or \code{'rb'} when the file must be opened for reading, or \code{'w'}  | 
					
						
							|  |  |  | or \code{'wb'} when the file must be opened for writing.  If omitted, | 
					
						
							|  |  |  | \code{\var{file}.mode} is used if it exists, otherwise \code{'rb'} is | 
					
						
							|  |  |  | used.  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 \method{writeframesraw()} and \method{setnframes()}. | 
					
						
							| 
									
										
										
										
											1994-09-29 16:46:42 +00:00
										 |  |  | \end{funcdesc} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1998-04-04 07:15:02 +00:00
										 |  |  | Objects returned by \function{open()} when a file is opened for | 
					
						
							| 
									
										
										
										
											1994-09-29 16:46:42 +00:00
										 |  |  | reading have the following methods: | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1998-04-04 07:15:02 +00:00
										 |  |  | \begin{methoddesc}[aifc]{getnchannels}{} | 
					
						
							| 
									
										
										
										
											1994-09-29 16:46:42 +00:00
										 |  |  | Return the number of audio channels (1 for mono, 2 for stereo). | 
					
						
							| 
									
										
										
										
											1998-04-04 07:15:02 +00:00
										 |  |  | \end{methoddesc} | 
					
						
							| 
									
										
										
										
											1994-09-29 16:46:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1998-04-04 07:15:02 +00:00
										 |  |  | \begin{methoddesc}[aifc]{getsampwidth}{} | 
					
						
							| 
									
										
										
										
											1994-09-29 16:46:42 +00:00
										 |  |  | Return the size in bytes of individual samples. | 
					
						
							| 
									
										
										
										
											1998-04-04 07:15:02 +00:00
										 |  |  | \end{methoddesc} | 
					
						
							| 
									
										
										
										
											1994-09-29 16:46:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1998-04-04 07:15:02 +00:00
										 |  |  | \begin{methoddesc}[aifc]{getframerate}{} | 
					
						
							| 
									
										
										
										
											1994-09-29 16:46:42 +00:00
										 |  |  | Return the sampling rate (number of audio frames per second). | 
					
						
							| 
									
										
										
										
											1998-04-04 07:15:02 +00:00
										 |  |  | \end{methoddesc} | 
					
						
							| 
									
										
										
										
											1994-09-29 16:46:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1998-04-04 07:15:02 +00:00
										 |  |  | \begin{methoddesc}[aifc]{getnframes}{} | 
					
						
							| 
									
										
										
										
											1994-09-29 16:46:42 +00:00
										 |  |  | Return the number of audio frames in the file. | 
					
						
							| 
									
										
										
										
											1998-04-04 07:15:02 +00:00
										 |  |  | \end{methoddesc} | 
					
						
							| 
									
										
										
										
											1994-09-29 16:46:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1998-04-04 07:15:02 +00:00
										 |  |  | \begin{methoddesc}[aifc]{getcomptype}{} | 
					
						
							| 
									
										
										
										
											1994-09-29 16:46:42 +00: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 07:15:02 +00:00
										 |  |  | \end{methoddesc} | 
					
						
							| 
									
										
										
										
											1994-09-29 16:46:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1998-04-04 07:15:02 +00:00
										 |  |  | \begin{methoddesc}[aifc]{getcompname}{} | 
					
						
							| 
									
										
										
										
											1994-09-29 16:46:42 +00: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 07:15:02 +00:00
										 |  |  | \end{methoddesc} | 
					
						
							| 
									
										
										
										
											1994-09-29 16:46:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1998-04-04 07:15:02 +00:00
										 |  |  | \begin{methoddesc}[aifc]{getparams}{} | 
					
						
							| 
									
										
										
										
											1994-09-29 16:46:42 +00:00
										 |  |  | Return a tuple consisting of all of the above values in the above | 
					
						
							|  |  |  | order. | 
					
						
							| 
									
										
										
										
											1998-04-04 07:15:02 +00:00
										 |  |  | \end{methoddesc} | 
					
						
							| 
									
										
										
										
											1994-09-29 16:46:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1998-04-04 07:15:02 +00:00
										 |  |  | \begin{methoddesc}[aifc]{getmarkers}{} | 
					
						
							| 
									
										
										
										
											1994-09-29 16:46:42 +00: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 07:15:02 +00:00
										 |  |  | \end{methoddesc} | 
					
						
							| 
									
										
										
										
											1994-09-29 16:46:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1998-04-04 07:15:02 +00: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 16:46:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1998-04-04 07:15:02 +00:00
										 |  |  | \begin{methoddesc}[aifc]{readframes}{nframes} | 
					
						
							| 
									
										
										
										
											1995-03-13 10:03:32 +00:00
										 |  |  | Read and return the next \var{nframes} frames from the audio file.  The | 
					
						
							| 
									
										
										
										
											1994-09-29 16:46:42 +00:00
										 |  |  | returned data is a string containing for each frame the uncompressed | 
					
						
							|  |  |  | samples of all channels. | 
					
						
							| 
									
										
										
										
											1998-04-04 07:15:02 +00:00
										 |  |  | \end{methoddesc} | 
					
						
							| 
									
										
										
										
											1994-09-29 16:46:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1998-04-04 07:15:02 +00:00
										 |  |  | \begin{methoddesc}[aifc]{rewind}{} | 
					
						
							|  |  |  | Rewind the read pointer.  The next \method{readframes()} will start from | 
					
						
							| 
									
										
										
										
											1994-09-29 16:46:42 +00:00
										 |  |  | the beginning. | 
					
						
							| 
									
										
										
										
											1998-04-04 07:15:02 +00:00
										 |  |  | \end{methoddesc} | 
					
						
							| 
									
										
										
										
											1994-09-29 16:46:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1998-04-04 07:15:02 +00:00
										 |  |  | \begin{methoddesc}[aifc]{setpos}{pos} | 
					
						
							| 
									
										
										
										
											1994-09-29 16:46:42 +00:00
										 |  |  | Seek to the specified frame number. | 
					
						
							| 
									
										
										
										
											1998-04-04 07:15:02 +00:00
										 |  |  | \end{methoddesc} | 
					
						
							| 
									
										
										
										
											1994-09-29 16:46:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1998-04-04 07:15:02 +00:00
										 |  |  | \begin{methoddesc}[aifc]{tell}{} | 
					
						
							| 
									
										
										
										
											1994-09-29 16:46:42 +00:00
										 |  |  | Return the current frame number. | 
					
						
							| 
									
										
										
										
											1998-04-04 07:15:02 +00:00
										 |  |  | \end{methoddesc} | 
					
						
							| 
									
										
										
										
											1994-09-29 16:46:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1998-04-04 07:15:02 +00:00
										 |  |  | \begin{methoddesc}[aifc]{close}{} | 
					
						
							| 
									
										
										
										
											1994-09-29 16:46:42 +00:00
										 |  |  | Close the AIFF file.  After calling this method, the object can no | 
					
						
							|  |  |  | longer be used. | 
					
						
							| 
									
										
										
										
											1998-04-04 07:15:02 +00:00
										 |  |  | \end{methoddesc} | 
					
						
							| 
									
										
										
										
											1994-09-29 16:46:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1998-04-04 07:15:02 +00: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 16:46:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1998-04-04 07:15:02 +00:00
										 |  |  | \begin{methoddesc}[aifc]{aiff}{} | 
					
						
							| 
									
										
										
										
											1994-09-29 16:46:42 +00:00
										 |  |  | Create an AIFF file.  The default is that an AIFF-C file is created, | 
					
						
							| 
									
										
										
										
											1998-02-13 22:22:36 +00:00
										 |  |  | unless the name of the file ends in \code{'.aiff'} in which case the | 
					
						
							|  |  |  | default is an AIFF file. | 
					
						
							| 
									
										
										
										
											1998-04-04 07:15:02 +00:00
										 |  |  | \end{methoddesc} | 
					
						
							| 
									
										
										
										
											1994-09-29 16:46:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1998-04-04 07:15:02 +00:00
										 |  |  | \begin{methoddesc}[aifc]{aifc}{} | 
					
						
							| 
									
										
										
										
											1994-09-29 16:46:42 +00:00
										 |  |  | Create an AIFF-C file.  The default is that an AIFF-C file is created, | 
					
						
							| 
									
										
										
										
											1998-02-13 22:22:36 +00:00
										 |  |  | unless the name of the file ends in \code{'.aiff'} in which case the | 
					
						
							|  |  |  | default is an AIFF file. | 
					
						
							| 
									
										
										
										
											1998-04-04 07:15:02 +00:00
										 |  |  | \end{methoddesc} | 
					
						
							| 
									
										
										
										
											1994-09-29 16:46:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1998-04-04 07:15:02 +00:00
										 |  |  | \begin{methoddesc}[aifc]{setnchannels}{nchannels} | 
					
						
							| 
									
										
										
										
											1994-09-29 16:46:42 +00:00
										 |  |  | Specify the number of channels in the audio file. | 
					
						
							| 
									
										
										
										
											1998-04-04 07:15:02 +00:00
										 |  |  | \end{methoddesc} | 
					
						
							| 
									
										
										
										
											1994-09-29 16:46:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1998-04-04 07:15:02 +00:00
										 |  |  | \begin{methoddesc}[aifc]{setsampwidth}{width} | 
					
						
							| 
									
										
										
										
											1994-09-29 16:46:42 +00:00
										 |  |  | Specify the size in bytes of audio samples. | 
					
						
							| 
									
										
										
										
											1998-04-04 07:15:02 +00:00
										 |  |  | \end{methoddesc} | 
					
						
							| 
									
										
										
										
											1994-09-29 16:46:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1998-04-04 07:15:02 +00:00
										 |  |  | \begin{methoddesc}[aifc]{setframerate}{rate} | 
					
						
							| 
									
										
										
										
											1994-09-29 16:46:42 +00:00
										 |  |  | Specify the sampling frequency in frames per second. | 
					
						
							| 
									
										
										
										
											1998-04-04 07:15:02 +00:00
										 |  |  | \end{methoddesc} | 
					
						
							| 
									
										
										
										
											1994-09-29 16:46:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1998-04-04 07:15:02 +00:00
										 |  |  | \begin{methoddesc}[aifc]{setnframes}{nframes} | 
					
						
							| 
									
										
										
										
											1994-09-29 16:46:42 +00: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 07:15:02 +00:00
										 |  |  | \end{methoddesc} | 
					
						
							| 
									
										
										
										
											1994-09-29 16:46:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1998-04-04 07:15:02 +00:00
										 |  |  | \begin{methoddesc}[aifc]{setcomptype}{type, name} | 
					
						
							| 
									
										
										
										
											1994-09-29 16:46:42 +00: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 07:15:02 +00:00
										 |  |  | \index{u-LAW} | 
					
						
							|  |  |  | \index{A-LAW} | 
					
						
							|  |  |  | \index{G.722} | 
					
						
							|  |  |  | \end{methoddesc} | 
					
						
							| 
									
										
										
										
											1994-09-29 16:46:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1998-04-04 07:15:02 +00:00
										 |  |  | \begin{methoddesc}[aifc]{setparams}{nchannels, sampwidth, framerate, comptype, compname} | 
					
						
							| 
									
										
										
										
											1994-09-29 16:46:42 +00: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 07:15:02 +00:00
										 |  |  | to use the result of a \method{getparams()} call as argument to | 
					
						
							|  |  |  | \method{setparams()}. | 
					
						
							|  |  |  | \end{methoddesc} | 
					
						
							| 
									
										
										
										
											1994-09-29 16:46:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1998-04-04 07:15:02 +00:00
										 |  |  | \begin{methoddesc}[aifc]{setmark}{id, pos, name} | 
					
						
							| 
									
										
										
										
											1994-09-29 16:46:42 +00: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 07:15:02 +00:00
										 |  |  | \method{close()}. | 
					
						
							|  |  |  | \end{methoddesc} | 
					
						
							| 
									
										
										
										
											1994-09-29 16:46:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1998-04-04 07:15:02 +00:00
										 |  |  | \begin{methoddesc}[aifc]{tell}{} | 
					
						
							| 
									
										
										
										
											1994-09-29 16:46:42 +00:00
										 |  |  | Return the current write position in the output file.  Useful in | 
					
						
							| 
									
										
										
										
											1998-04-04 07:15:02 +00:00
										 |  |  | combination with \method{setmark()}. | 
					
						
							|  |  |  | \end{methoddesc} | 
					
						
							| 
									
										
										
										
											1994-09-29 16:46:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1998-04-04 07:15:02 +00:00
										 |  |  | \begin{methoddesc}[aifc]{writeframes}{data} | 
					
						
							| 
									
										
										
										
											1994-09-29 16:46:42 +00:00
										 |  |  | Write data to the output file.  This method can only be called after | 
					
						
							|  |  |  | the audio file parameters have been set. | 
					
						
							| 
									
										
										
										
											1998-04-04 07:15:02 +00:00
										 |  |  | \end{methoddesc} | 
					
						
							| 
									
										
										
										
											1994-09-29 16:46:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1998-04-04 07:15:02 +00: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 16:46:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1998-04-04 07:15:02 +00:00
										 |  |  | \begin{methoddesc}[aifc]{close}{} | 
					
						
							| 
									
										
										
										
											1994-09-29 16:46:42 +00:00
										 |  |  | Close the AIFF file.  The header of the file is updated to reflect the | 
					
						
							| 
									
										
										
										
											1995-03-13 10:03:32 +00:00
										 |  |  | actual size of the audio data. After calling this method, the object | 
					
						
							| 
									
										
										
										
											1994-09-29 16:46:42 +00:00
										 |  |  | can no longer be used. | 
					
						
							| 
									
										
										
										
											1998-04-04 07:15:02 +00:00
										 |  |  | \end{methoddesc} |