Audio Queue Serviceプログラミングガイド

音声の記録

Audio Queue Serviceで録音する場合、その保存先(the destination)はディスク上のファイル、ネットワーク接続の先、メモリ上のオブジェクトなど、殆ど何でも選択することが出来ます。 本章では最も一般的なシナリオ、ディスク上のファイルへの基礎的な録音方法を解説します。

本文章のコード例は、Core Audio SDKのC++クラスを使って、しばしば単純化されています。 しかし、Audio Queue Serviceの利用にあたって、Core Audio SDKもC++言語も必須ではありません。 同様の理由で、コードにはしっかりとしたエラー処理が含まれていません。 Audio Queue Serviceを用いた録音/再生機能を実装する場合は、潜在的なエラーを扱うコードを確実に追加して下さい。

アプリケーションに録音機能を追加するには、通常、以下の段階を踏みます:

  1. 状態(state)、形式(format)、パス情報を管理する独自構造体を定義する。
  2. 実際の録音作業を行うAudio Queueコールバック関数を記述する。
  3. Audio Queue Bufferの最適サイズを決めるコードを任意で記述する。マジッククッキーが必要な形式で録音する場合は、マジッククッキーを扱うコードを書く。
  4. 独自構造体のフィールドを埋める。This includes specifying the data stream that the audio queue sends to the file it’s recording into, as well as the path to that file.
  5. 録音用Audio Queueを生成し、Audio Queueに対してAudio Queue Bufferを生成するよう指示する。また、録音先のファイルを生成する。
  6. Audio Queueに録音開始を伝える。
  7. 録音が終わったら、Audio Queueに停止を伝え、それからAudio Queueを破棄する。そのAudio QueueはAudio Queue Bufferを(自動的に)破棄する。

本章の残りで、これらそれぞれのステップを詳解します。

状態管理用の独自構造体の定義

Audio Queue Serviceを用いた録音機能開発の第一歩は、独自構造体を定義することです。 この構造体を使って、オーディオ形式とAudio Queueの状態の情報を管理することになります。 リスト 2-1は構造体の例です。

リスト 2-1 録音用Audio Queueの独自構造体

static const int kNumberBuffers = 3;                            // 1
struct AQRecorderState {
    AudioStreamBasicDescription  mDataFormat;                   // 2
    AudioQueueRef                mQueue;                        // 3
    AudioQueueBufferRef          mBuffers[kNumberBuffers];      // 4
    AudioFileID                  mAudioFile;                    // 5
    UInt32                       bufferByteSize;                // 6
    SInt64                       mCurrentPacket;                // 7
    bool                         mIsRunning;                    // 8
};

では、この構造体のフィールドの解説をしましょう:

  1. 使用するAudio Queue Bufferの個数の設定です。
  2. AudioStreamBasicDescription構造体(定義場所 CoreAudioTypes.h)は、ディスクに書き出す音声形式を表します。この形式はmQueueフィールドで指定されるAudio Queueで使用します。

2.

    An AudioStreamBasicDescription structure (from CoreAudioTypes.h) representing the audio data format to write to disk. This format gets used by the audio queue specified in the mQueue field.
    The mDataFormat field gets filled initially by code in your program, as described in “Set Up an Audio Format for Recording.” It is good practice to then update the value of this field by querying the audio queue's kAudioConverterCurrentOutputStreamDescription property, as described in “Getting the Full Audio Format from an Audio Queue.”
    For details on the AudioStreamBasicDescription structure, see Core Audio Data Types Reference.
 3.
    The recording audio queue created by your application.
 4.
    An array holding pointers to the audio queue buffers managed by the audio queue.
 5.
    An audio file object representing the file into which your program records audio data.
 6.
    The size, in bytes, for each audio queue buffer. This value is calculated in these examples in the DeriveBufferSize function, after the audio queue is created and before it is started. See “Write a Function to Derive Recording Audio Queue Buffer Size.”
 7.
    The packet index for the first packet to be written from the current audio queue buffer.
 8.
    A Boolean value indicating whether or not the audio queue is running.
 
翻訳文章/オーディオ/audio_queue_serviceプログラミングガイド/音声の記録.txt · 最終更新: 2009/05/20 17:36 by decomo
 
特に明示されていない限り、本Wikiの内容は次のライセンスに従います:CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki