"aifc" — AIFFおよびAIFCファイルの読み書き
*****************************************

**ソースコード:** Lib/aifc.py

======================================================================

このモジュールはAIFFとAIFF-Cファイルの読み書きをサポートします。AIFF（
Audio Interchange File Format）はデジタルオーディオサンプルをファイル
に保存するためのフォーマットです。AIFF-CはAIFFの新しいバージョンで、オ
ーディオデータの圧縮に対応しています。

注釈: 操作のいくつかはIRIX上でのみ動作します; そういう操作ではIRIXで
  のみ利 用できる "cl" モジュールをインポートしようとして、
  "ImportError" を 発生します。

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
frame consists of *nchannels***samplesize* bytes, and a second’s worth
of audio consists of *nchannels***samplesize***framerate* bytes.

例えば、CD品質のオーディオは2バイト（16ビット）のサンプルサイズを持っ
ていて、2チャンネル（ステレオ）であり、44,100フレーム／秒のフレームレ
ートを持っています。そのため、フレームサイズは4バイト（2*2）で、1秒間
では2*2*44100バイト（176,400バイト）になります。

"aifc" モジュールは以下の関数を定義しています:

aifc.open(file[, mode])

   Open an AIFF or AIFF-C file and return an object instance with
   methods that are described below.  The argument *file* is either a
   string naming a file or a file object.  *mode* must be "'r'" or
   "'rb'" when the file must be opened for reading, or "'w'"  or
   "'wb'" when the file must be opened for writing.  If omitted,
   "file.mode" is used if it exists, otherwise "'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 "writeframesraw()" and "setnframes()".

ファイルが "open()" によって読み込み用に開かれたときに返されるオブジェ
クトには、以下のメソッドがあります:

aifc.getnchannels()

   オーディオチャンネル数（モノラルなら1、ステレオなら2）を返します。

aifc.getsampwidth()

   サンプルサイズをバイト数で返します。

aifc.getframerate()

   サンプリングレート（1秒あたりのオーディオフレーム数）を返します。

aifc.getnframes()

   ファイルの中のオーディオフレーム数を返します。

aifc.getcomptype()

   Return a four-character string describing the type of compression
   used in the audio file.  For AIFF files, the returned value is
   "'NONE'".

aifc.getcompname()

   Return a human-readable description of the type of compression used
   in the audio file.  For AIFF files, the returned value is "'not
   compressed'".

aifc.getparams()

   Return a tuple consisting of all of the above values in the above
   order.

aifc.getmarkers()

   オーディオファイルのマーカーのリストを返します。一つのマーカーは三
   つの要素のタプルです。要素の1番目はマークID（整数）、2番目はマーク
   位置のフレーム数をデータの始めから数えた値（整数）、3番目はマークの
   名称（文字列）です。

aifc.getmark(id)

   与えられた *id* のマークの要素を "getmarkers()" で述べたタプルで返
   します。

aifc.readframes(nframes)

   オーディオファイルの次の *nframes* 個のフレームを読み込んで返します
   。返されるデータは、全チャンネルの圧縮されていないサンプルをフレー
   ムごとに文字列にしたものです。

aifc.rewind()

   読み込むポインタをデータの始めに巻き戻します。次に "readframes()"
   を使用すると、データの始めから読み込みます。

aifc.setpos(pos)

   指定したフレーム数の位置にポインタを設定します。

aifc.tell()

   現在のポインタのフレーム位置を返します。

aifc.close()

   AIFFファイルを閉じます。このメソッドを呼び出したあとでは、オブジェ
   クトはもう使用できません。

ファイルが "open()" によって書き込み用に開かれたときに返されるオブジェ
クトには、 "readframes()" と "setpos()" を除く上述の全てのメソッドがあ
ります。さらに以下のメソッドが定義されています。 "get*()" メソッドは、
対応する "set*()" を呼び出したあとでのみ呼び出し可能です。最初に
"writeframes()" あるいは "writeframesraw()" を呼び出す前に、フレーム数
を除く全てのパラメータが設定されていなければなりません。

aifc.aiff()

   AIFFファイルを作ります。デフォルトではAIFF-Cファイルが作られますが
   、ファイル名が "'.aiff'" で終わっていればAIFFファイルが作られます。

aifc.aifc()

   AIFF-Cファイルを作ります。デフォルトではAIFF-Cファイルが作られます
   が、ファイル名が "'.aiff'" で終わっていればAIFFファイルが作られます
   。

aifc.setnchannels(nchannels)

   オーディオファイルのチャンネル数を設定します。

aifc.setsampwidth(width)

   オーディオのサンプルサイズをバイト数で設定します。

aifc.setframerate(rate)

   サンプリングレートを1秒あたりのフレーム数で設定します。

aifc.setnframes(nframes)

   オーディオファイルに書き込まれるフレーム数を設定します。もしこのパ
   ラメータが設定されていなかったり正しくなかったら、ファイルはシーク
   に対応していなければなりません。

aifc.setcomptype(type, name)

   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.

aifc.setparams(nchannels, sampwidth, framerate, comptype, compname)

   上の全パラメータを一度に設定します。引数はそれぞれのパラメータから
   なるタプルです。つまり、 "setparams()" の引数として、 "getparams()"
   を呼び出した結果を使うことができます。

aifc.setmark(id, pos, name)

   指定したID（1以上）、位置、名称でマークを加えます。このメソッドは、
   "close()" の前ならいつでも呼び出すことができます。

aifc.tell()

   出力ファイルの現在の書き込み位置を返します。 "setmark()" との組み合
   わせで使うと便利です。

aifc.writeframes(data)

   出力ファイルにデータを書き込みます。このメソッドは、オーディオファ
   イルのパラメータを設定したあとでのみ呼び出し可能です。

aifc.writeframesraw(data)

   オーディオファイルのヘッダ情報が更新されないことを除いて、
   "writeframes()" と同じです。

aifc.close()

   AIFFファイルを閉じます。ファイルのヘッダ情報は、オーディオデータの
   実際のサイズを反映して更新されます。このメソッドを呼び出したあとで
   は、オブジェクトはもう使用できません。
