原文 Audio Queue Services Programming Guide (http://developer.apple.com/documentation/MusicAudio/Conceptual/AudioQueueProgrammingGuide/index.html)
Audio Queue Serviceで録音する場合、その保存先(the destination)はディスク上のファイル、ネットワーク接続の先、メモリ上のオブジェクトなど、殆ど何でも選択することが出来ます。
本章では最も一般的なシナリオ、ディスク上のファイルへの基礎的な録音方法を解説します。
アプリケーションに録音機能を追加するには、通常、以下の段階を踏みます:
本章の残りで、これらそれぞれのステップを詳解します。
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
};
では、この構造体のフィールドの解説をしましょう:
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.