差分
このページの2つのバージョン間の差分を表示します。
両方とも前のリビジョン 前のリビジョン 次のリビジョン | 前のリビジョン | ||
translation:adc:audio:audio_queue_services_programming_guide:0300_recordingaudio [2014-09-01 19:14] Decomo |
translation:adc:audio:audio_queue_services_programming_guide:0300_recordingaudio [2020-12-04 09:32] (現在) Decomo |
||
---|---|---|---|
行 1: | 行 1: | ||
- | <align right> | + | <WRAP rightalign> |
※以前のwikiで本章は翻訳途中だったため、10.9のリファレンスから再翻訳しています。 | ※以前のwikiで本章は翻訳途中だったため、10.9のリファレンスから再翻訳しています。 | ||
行 44: | 行 44: | ||
- 使用するAudio Queue Bufferの数の設定。 | - 使用するAudio Queue Bufferの数の設定。 | ||
- | -- < | + | -- '' |
- | .. < | + | .. '' |
- | .. < | + | .. '' |
- あなたのアプリケーションによって生成される録音Audio Queue。 | - あなたのアプリケーションによって生成される録音Audio Queue。 | ||
- そのAudio Queueによって管理されるAudio Queue Bufferへのポインタの配列。 | - そのAudio Queueによって管理されるAudio Queue Bufferへのポインタの配列。 | ||
- プログラムが音声データを記録するファイルを表すAudio Fileオブジェクト。 | - プログラムが音声データを記録するファイルを表すAudio Fileオブジェクト。 | ||
- | - 各Audio Queue Bufferの大きさのバイト数。この値は、以下のサンプルの< | + | - 各Audio Queue Bufferの大きさのバイト数。この値は、以下のサンプルの'' |
- 現在のAudio Queue Bufferから書き出される最初のパケットのパケットインデックス。 | - 現在のAudio Queue Bufferから書き出される最初のパケットのパケットインデックス。 | ||
- Audio Queueが実行中かどうかを示すブール値。 | - Audio Queueが実行中かどうかを示すブール値。 | ||
行 67: | 行 67: | ||
==== 録音Audio Queueコールバックの宣言 ==== | ==== 録音Audio Queueコールバックの宣言 ==== | ||
- | リスト2-2は録音Audio Queueコールバック関数の宣言例で、< | + | リスト2-2は録音Audio Queueコールバック関数の宣言例で、'' |
**リスト 2-2** 録音Audio Queueコールバック宣言 | **リスト 2-2** 録音Audio Queueコールバック宣言 | ||
行 83: | 行 83: | ||
コードの働きを見てみましょう: | コードの働きを見てみましょう: | ||
- | - 典型的には< | + | - 典型的には'' |
- このコールバックを所持するAudio Queueです。 | - このコールバックを所持するAudio Queueです。 | ||
- 録音で入ってくる音声データを含むAudio Queue Bufferです。 | - 録音で入ってくる音声データを含むAudio Queue Bufferです。 | ||
- Audio Queue Bufferの先頭サンプルのサンプル時間です(簡易的な録音では必要ありません)。 | - Audio Queue Bufferの先頭サンプルのサンプル時間です(簡易的な録音では必要ありません)。 | ||
- | - < | + | - '' |
- パケット記述子を必要とする圧縮音声データ形式のための、バッファ内のパケット用のエンコーダが提示するパケット記述子。 | - パケット記述子を必要とする圧縮音声データ形式のための、バッファ内のパケット用のエンコーダが提示するパケット記述子。 | ||
行 94: | 行 94: | ||
録音Audio Queueコールバックの最初の仕事は、Audio Queue Bufferをディスクに書き出す事です。 | 録音Audio Queueコールバックの最初の仕事は、Audio Queue Bufferをディスクに書き出す事です。 | ||
このバッファは、たった今コールバックのAudio Queueが入力デバイスからの新しい音声データで埋めたものです。 | このバッファは、たった今コールバックのAudio Queueが入力デバイスからの新しい音声データで埋めたものです。 | ||
- | リスト2-3で示すように、コールバックは< | + | リスト2-3で示すように、コールバックは'' |
**リスト 2-3** Audio Queue Bufferをディスクに書き出す | **リスト 2-3** Audio Queue Bufferをディスクに書き出す | ||
行 111: | 行 111: | ||
コードの働きを見てみましょう: | コードの働きを見てみましょう: | ||
- | - < | + | - '' |
- | - 音声ファイルオブジェクト(< | + | - 音声ファイルオブジェクト('' |
- | - < | + | - '' |
- | - 書き出す音声データのバイト数です。< | + | - 書き出す音声データのバイト数です。'' |
- 音声データのパケット記述子配列です。NULLはパケット記述子が必要ない事を示します(CBRの音声データなど)。 | - 音声データのパケット記述子配列です。NULLはパケット記述子が必要ない事を示します(CBRの音声データなど)。 | ||
- 書き出す先頭パケットのパケットインデックスです。 | - 書き出す先頭パケットのパケットインデックスです。 | ||
行 137: | 行 137: | ||
コードの働きを見てみましょう: | コードの働きを見てみましょう: | ||
- | - < | + | - '' |
- | - 指定したAudio Queue Bufferを追加するAudio Queue。< | + | - 指定したAudio Queue Bufferを追加するAudio Queue。'' |
- キューに追加するAudio Queue Buffer。 | - キューに追加するAudio Queue Buffer。 | ||
- | - Audio Queue Bufferのデータのパケット記述子の数。本パラメータは録音では使わないので、< | + | - Audio Queue Bufferのデータのパケット記述子の数。本パラメータは録音では使わないので、'' |
- | - Audio Queue Bufferのデータのパケット記述子配列。本パラメータは録音では使わないので、< | + | - Audio Queue Bufferのデータのパケット記述子配列。本パラメータは録音では使わないので、'' |
行 240: | 行 240: | ||
- サイズを特定したいバッファを持つAudio Queue。 | - サイズを特定したいバッファを持つAudio Queue。 | ||
- | - Audio Queueの< | + | - Audio Queueの'' |
- 音声の秒数を単位とした、必要とするAudio Queue Bufferの大きさ。 | - 音声の秒数を単位とした、必要とするAudio Queue Bufferの大きさ。 | ||
- 出力で、バイト数を単位としたAudio Aueue Bufferのサイズ。 | - 出力で、バイト数を単位としたAudio Aueue Bufferのサイズ。 | ||
- Audio Queue Bufferサイズの上限(バイト数)。この例では320KBに設定されている。これはサンプリング周波数96kHz/ | - Audio Queue Bufferサイズの上限(バイト数)。この例では320KBに設定されている。これはサンプリング周波数96kHz/ | ||
- | - CBR音声データ用に、< | + | - CBR音声データ用に、'' |
- | - この割り当ては、その音声データの録音がCBRかVBRかを特定する副作用をもたらす。VBRならば、Audio Queueの< | + | - この割り当ては、その音声データの録音がCBRかVBRかを特定する副作用をもたらす。VBRならば、Audio Queueの'' |
- VBR音声データ用に、Audio Queueに見積もり最大パケットサイズを問い合わせる。 | - VBR音声データ用に、Audio Queueに見積もり最大パケットサイズを問い合わせる。 | ||
- バイト数でバッファサイズを計算する。 | - バイト数でバッファサイズを計算する。 | ||
行 303: | 行 303: | ||
- この関数の成否を表す返値変数。 | - この関数の成否を表す返値変数。 | ||
- マジッククッキーのデータサイズを保持する変数。 | - マジッククッキーのデータサイズを保持する変数。 | ||
- | - Audio Queueからマジッククッキーのデータサイズを取得し、< | + | - Audio Queueからマジッククッキーのデータサイズを取得し、'' |
- マジッククッキー情報を保持するバイト列を確保します。 | - マジッククッキー情報を保持するバイト列を確保します。 | ||
- | - Audio Queueの< | + | - Audio Queueの'' |
- | - 記録するAudio Fileにマジッククッキーを設定します。< | + | - 記録するAudio Fileにマジッククッキーを設定します。'' |
- 一時クッキー変数のメモリを解放します。 | - 一時クッキー変数のメモリを解放します。 | ||
- 関数の成否を返します。 | - 関数の成否を返します。 | ||
- | ===== 録音用音声フォーマットの構成 ===== | + | ===== 録音音声フォーマットの構成 ===== |
本項ではAudio Queueの音声データ形式の構成方法を説明します。 | 本項ではAudio Queueの音声データ形式の構成方法を説明します。 | ||
行 327: | 行 327: | ||
リスト2-8は、各属性を固定値とした録音用の音声形式の構成を示します。 | リスト2-8は、各属性を固定値とした録音用の音声形式の構成を示します。 | ||
製品コードでは、通常、音声形式の幾つかないし全ての項目をユーザーが設定できるようにすべきでしょう。 | 製品コードでは、通常、音声形式の幾つかないし全ての項目をユーザーが設定できるようにすべきでしょう。 | ||
- | いずれのアプローチでも、目的は“[[# | + | いずれのアプローチでも、目的は“[[# |
**リスト 2-8** Audio Queueの音声データ形式の指定 | **リスト 2-8** Audio Queueの音声データ形式の指定 | ||
行 338: | 行 338: | ||
aqData.mDataFormat.mBitsPerChannel | aqData.mDataFormat.mBitsPerChannel | ||
aqData.mDataFormat.mBytesPerPacket | aqData.mDataFormat.mBytesPerPacket | ||
- | aqData.mDataFormat.mBytesPerFrame = | + | aqData.mDataFormat.mBytesPerFrame |
- | aqData.mDataFormat.mChannelsPerFrame * sizeof (SInt16); | + | aqData.mDataFormat.mChannelsPerFrame * sizeof (SInt16); |
aqData.mDataFormat.mFramesPerPacket | aqData.mDataFormat.mFramesPerPacket | ||
行 351: | 行 351: | ||
コードの働きを見てみましょう: | コードの働きを見てみましょう: | ||
- | - < | + | - '' |
+ | - 音声データタイプをリニアPCMとして定義します。利用可能なデータ形式の完全なリストは// | ||
+ | - サンプリング周波数を44.1kHzとします。 | ||
+ | - チャンネル数は2とします。 | ||
+ | - チャンネルあたりのビット深度は16とします。 | ||
+ | - パケットあたりのバイト数とフレームあたりのバイト数は4とします(2チャンネル×サンプルあたり2バイト)。 | ||
+ | - パケットあたりのフレーム数は1とします。 | ||
+ | - ファイルタイプはAIFFとします。利用可能なファイルタイプの完全なリストは'' | ||
+ | - 特定のファイルタイプで必要となるフォーマットフラグを設定します。 | ||
- | Creates an instance of the AQRecorderState custom structure. The structure’s mDataFormat field contains an AudioStreamBasicDescription structure. The values set in the mDataFormat field provide an initial definition of the audio format for the audio queue—which is also the audio format for the file you record into. In Listing 2-10, you obtain a more complete specification of the audio format, which Core Audio provides to you based on the format type and file type. | + | ===== 録音Audio Queueの生成 ===== |
- | Defines the audio data format type as linear PCM. See Core Audio Data Types Reference for a complete listing of the available data formats. | + | それでは、録音コールバックと音声データ形式を設定して、録音Audio Queueの生成と設定をします。 |
- | Defines the sample rate as 44.1 kHz. | + | ==== 録音Audio Queueを生成する ==== |
- | Defines the number of channels as 2. | + | リスト2-9は録音Audio Queueの作り方を示したものです。 |
- | + | '' | |
- | Defines the bit depth per channel as 16. | + | |
- | + | ||
- | Defines the number of bytes per packet, and the number of bytes per frame, to 4 (that is, 2 channels times 2 bytes per sample). | + | |
- | + | ||
- | Defines the number of frames per packet as 1. | + | |
- | + | ||
- | Defines the file type as AIFF. See the audio file types enumeration in the AudioFile.h header file for a complete listing of the available file types. You can specify any file type for which there is an installed codec, as described in “Using Codecs and Audio Data Formats.” | + | |
- | + | ||
- | Sets the format flags needed for the specified file type. | + | |
- | + | ||
- | Create a Recording | + | |
- | + | ||
- | Now, with the recording callback and audio data format set up, you create and configure an audio queue for recording. | + | |
- | Creating a Recording Audio Queue | + | |
- | + | ||
- | Listing 2-9 illustrates how to create a recording audio queue. Notice that the AudioQueueNewInput | + | |
- | + | ||
- | Listing 2-9 Creating a recording audio queue | + | |
+ | **リスト 2-9** 録音Audio Queueの生成 | ||
+ | <code c_mac> | ||
AudioQueueNewInput ( // 1 | AudioQueueNewInput ( // 1 | ||
- | |||
& | & | ||
- | |||
HandleInputBuffer, | HandleInputBuffer, | ||
- | |||
& | & | ||
- | |||
NULL, // 5 | NULL, // 5 | ||
- | |||
kCFRunLoopCommonModes, | kCFRunLoopCommonModes, | ||
- | |||
0, // 7 | 0, // 7 | ||
- | |||
& | & | ||
- | |||
); | ); | ||
+ | </ | ||
- | Here’s how this code works: | + | コードの働きを見てみましょう: |
- | The AudioQueueNewInput function creates a new recording audio queue. | + | - '' |
+ | - 録音に使う音声データ形式です。“[[# | ||
+ | - 録音Audio Queueが使うコールバック関数です。“[[# | ||
+ | - 録音Audio Queueの独自データ構造体です。“[[# | ||
+ | - コールバックを呼び出す実行ループを指定します。'' | ||
+ | - コールバック呼び出しの実行ループモードです。通常、ここには'' | ||
+ | - 将来拡張用です。'' | ||
+ | - 新たに確保された録音Audio Queueが出力されます。 | ||
- | The audio data format to use for the recording. See “Set Up an Audio Format for Recording.” | + | ==== Audio Queueから完全な音声形式を取得する ==== |
- | The callback function to use with the recording audio queue. See “Write a Recording | + | Audio Queueの実体が出来ると(“[[#録音Audio Queueの生成]]”をご覧下さい)、Audio Queueは特に圧縮フォーマットにおいて、あなたが持っているものより完全に'' |
+ | 完全なフォーマット記述を取得するには、リスト2-10で示すように'' | ||
+ | 記録先のAudio Fileを作る際は、その完全な音声フォーマットをしようします(“[[# | ||
- | The custom data structure for the recording audio queue. See “Define a Custom Structure to Manage State.” | + | **リスト |
- | + | ||
- | The run loop on which the callback will be invoked. Use NULL to specify default behavior, in which the callback will be invoked on a thread internal to the audio queue. This is typical use—it allows the audio queue to record while your application’s user interface thread waits for user input to stop the recording. | + | |
- | + | ||
- | The run loop modes in which the callback can be invoked. Normally, use the kCFRunLoopCommonModes constant here. | + | |
- | + | ||
- | Reserved. Must be 0. | + | |
- | + | ||
- | On output, the newly allocated recording audio queue. | + | |
- | + | ||
- | Getting the Full Audio Format from an Audio Queue | + | |
- | + | ||
- | When the audio queue came into existence (see “Creating a Recording Audio Queue”), it may have filled out the AudioStreamBasicDescription structure more completely than you have, particularly for compressed formats. To obtain the complete format description, | + | |
- | + | ||
- | Listing 2-10 Getting the audio format from an audio queue | + | |
+ | <code c_mac> | ||
UInt32 dataFormatSize = sizeof (aqData.mDataFormat); | UInt32 dataFormatSize = sizeof (aqData.mDataFormat); | ||
- | |||
- | |||
AudioQueueGetProperty ( // 2 | AudioQueueGetProperty ( // 2 | ||
- | |||
aqData.mQueue, | aqData.mQueue, | ||
- | |||
kAudioQueueProperty_StreamDescription, | kAudioQueueProperty_StreamDescription, | ||
- | + | | |
- | | + | |
// kAudioConverterCurrentInputStreamDescription | // kAudioConverterCurrentInputStreamDescription | ||
- | |||
& | & | ||
- | |||
& | & | ||
- | |||
); | ); | ||
+ | </ | ||
+ | コードの働きを見てみましょう: | ||
- | Here’s how this code works: | + | - Audio Queueに音声データ形式を問い合わせる時に使う、プロパティ値の期待サイズを得ます。 |
+ | - '' | ||
+ | - 音声データ形式を取得するAudio Queueです。 | ||
+ | - Audio Queueのデータ形式値を得るためのプロパティIDです。 | ||
+ | - 出力で、Audio Queueから得られた'' | ||
+ | - 入力では、'' | ||
- | Gets an expected property value size to use when querying the audio queue about its audio data format. | + | ===== Audio Fileの生成 ===== |
- | The AudioQueueGetProperty function obtains the value for a specified property in an audio queue. | + | 生成と設定が行われたAudio Queueを使って、リスト2-11のように録音データを保存するAudio Fileを生成します。 |
+ | Audio Fileは、前述のAudio Queueの独自構造体に格納されたデータ形式とファイル形式仕様を使います。 | ||
- | The audio queue to obtain the audio data format from. | + | **リスト |
- | + | ||
- | The property ID for obtaining the value of the audio queue’s data format. | + | |
- | + | ||
- | On output, the full audio data format, in the form of an AudioStreamBasicDescription structure, obtained from the audio queue. | + | |
- | + | ||
- | On input, the expected size of the AudioStreamBasicDescription structure. On output, the actual size. Your recording application does not need to make use of this value. | + | |
- | + | ||
- | Create an Audio File | + | |
- | + | ||
- | With an audio queue created and configured, you create the audio file that you’ll record audio data into, as shown in Listing | + | |
- | + | ||
- | Listing 2-11 Creating an audio file for recording | + | |
+ | <code c_mac> | ||
CFURLRef audioFileURL = | CFURLRef audioFileURL = | ||
- | |||
CFURLCreateFromFileSystemRepresentation ( // 1 | CFURLCreateFromFileSystemRepresentation ( // 1 | ||
- | |||
NULL, // 2 | NULL, // 2 | ||
- | |||
(const UInt8 *) filePath, | (const UInt8 *) filePath, | ||
- | |||
strlen (filePath), | strlen (filePath), | ||
- | |||
false // 5 | false // 5 | ||
- | |||
); | ); | ||
- | |||
- | |||
AudioFileCreateWithURL ( // 6 | AudioFileCreateWithURL ( // 6 | ||
- | |||
audioFileURL, | audioFileURL, | ||
- | |||
fileType, | fileType, | ||
- | |||
& | & | ||
- | |||
kAudioFileFlags_EraseFile, | kAudioFileFlags_EraseFile, | ||
- | |||
& | & | ||
- | |||
); | ); | ||
+ | </ | ||
- | Here’s how this code works: | + | コードの働きを見てみましょう: |
- | The CFURLCreateFromFileSystemRepresentation function, declared in the CFURL.h | + | - '' |
+ | - '' | ||
+ | - '' | ||
+ | - ファイルシステムパスのバイト数です。 | ||
+ | - '' | ||
+ | - '' | ||
+ | - 新規音声ファイルの作成、もしくは既存ファイルの初期化の対象となるURLです。URLは手順1の[[https:// | ||
+ | - 新しいファイルのファイルタイプです。本章のサンプルコードでは、前に'' | ||
+ | - '' | ||
+ | - ファイルが既に存在していた場合、そのファイルを消します。 | ||
+ | - 出力で、記録先の音声ファイルを表す('' | ||
- | Use NULL (or kCFAllocatorDefault) to use the current default memory allocator. | + | ===== Audio Queue Bufferサイズの設定 ===== |
- | The file-system path you want to convert to a CFURL object. In production code, you would typically obtain a value for filePath from the user. | + | 録音中に使うAudio Queue Bufferセットを準備する前に、先に書いた'' |
+ | このサイズを使用する録音Audio Queueのサイズに割り当てます。 | ||
+ | リスト2-12がその様子を示します: | ||
- | The number of bytes in the file-system path. | + | **リスト 2-12** Audio Queue Bufferサイズの設定 |
- | + | ||
- | A value of false indicates that filePath represents a file, not a directory. | + | |
- | + | ||
- | The AudioFileCreateWithURL function, from the AudioFile.h header file, creates a new audio file or initializes an existing file. | + | |
- | + | ||
- | The URL at which to create the new audio file, or to initialize in the case of an existing file. The URL was derived from the CFURLCreateFromFileSystemRepresentation in step 1. | + | |
- | + | ||
- | The file type for the new file. In the example code in this chapter, this was previously set to AIFF by way of the kAudioFileAIFFType file type constant. See “Set Up an Audio Format for Recording.” | + | |
- | + | ||
- | The data format of the audio that will be recorded into the file, specified as an AudioStreamBasicDescription structure. In the example code for this chapter, this was also set in “Set Up an Audio Format for Recording.” | + | |
- | + | ||
- | Erases the file, in the case that the file already exists. | + | |
- | + | ||
- | On output, an audio file object (of type AudioFileID) representing the audio file to record into. | + | |
- | + | ||
- | Set an Audio Queue Buffer | + | |
- | + | ||
- | Before you prepare a set of audio queue buffers that you’ll use while recording, you make use of the DeriveBufferSize function you wrote earlier (see “Write a Function to Derive Recording Audio Queue Buffer Size”). You assign this size to the recording audio queue you are using. Listing 2-12 illustrates this: | + | |
- | + | ||
- | Listing 2-12 Setting an audio queue buffer size | + | |
+ | <code c_mac> | ||
DeriveBufferSize ( // 1 | DeriveBufferSize ( // 1 | ||
- | |||
aqData.mQueue, | aqData.mQueue, | ||
- | |||
aqData.mDataFormat, | aqData.mDataFormat, | ||
- | |||
0.5, // 4 | 0.5, // 4 | ||
- | |||
& | & | ||
- | |||
); | ); | ||
+ | </ | ||
- | Here’s how this code works: | + | コードの働きを見てみましょう: |
- | The DeriveBufferSize function, described in “Write a Function to Derive Recording | + | - “[[#録音Audio Queue Bufferサイズを計算する関数の実装]]”で解説した'' |
+ | - バッファサイズを設定するAudio Queueです。 | ||
+ | - 記録するファイルの音声データ形式です。“[[# | ||
+ | - 各Audio Queue Bufferが保持する音声の秒数です。通常、ここで設定している0.5秒が良い選択です。 | ||
+ | - 出力で、各Audio Queue Bufferサイズがバイト数で返ります。この値はAudio Queueの独自構造体の中に置かれます。 | ||
- | The audio queue that you’re setting buffer size for. | + | ===== Audio Queue Bufferセットの準備 ===== |
- | The audio data format for the file you are recording. See “Set Up an Audio Format for Recording.” | + | それでは、(“[[#録音Audio Queueの生成]]”で)生成したAudio Queueに、Audio Queue Bufferセットを準備するように命令します。 |
- | + | リスト | |
- | The number of seconds of audio that each audio queue buffer should hold. One half second, as set here, is typically a good choice. | + | |
- | + | ||
- | On output, the size for each audio queue buffer, in bytes. This value is placed in the custom structure for the audio queue. | + | |
- | + | ||
- | Prepare a Set of Audio Queue Buffers | + | |
- | + | ||
- | You now ask the audio queue that you’ve created (in “Create a Recording | + | |
- | + | ||
- | Listing | + | |
+ | **リスト 2-13** Audio Queue Bufferセットの準備 | ||
+ | <code c_mac> | ||
for (int i = 0; i < kNumberBuffers; | for (int i = 0; i < kNumberBuffers; | ||
- | |||
AudioQueueAllocateBuffer ( // 2 | AudioQueueAllocateBuffer ( // 2 | ||
- | |||
aqData.mQueue, | aqData.mQueue, | ||
- | |||
aqData.bufferByteSize, | aqData.bufferByteSize, | ||
- | |||
& | & | ||
- | |||
); | ); | ||
- | |||
- | |||
AudioQueueEnqueueBuffer ( // 6 | AudioQueueEnqueueBuffer ( // 6 | ||
- | |||
aqData.mQueue, | aqData.mQueue, | ||
- | |||
aqData.mBuffers[i], | aqData.mBuffers[i], | ||
- | |||
0, // 9 | 0, // 9 | ||
- | |||
NULL // 10 | NULL // 10 | ||
- | |||
); | ); | ||
- | |||
} | } | ||
+ | </ | ||
- | Here’s how this code works: | + | コードの働きを見てみましょう: |
- | Iterates to allocate and enqueue each audio queue buffer. | + | - Audio Queue Buffer確保とキュー追加のためにイテレートします。 |
+ | - '' | ||
+ | - バッファを確保し所持するAudio Queueです。 | ||
+ | - 新しく確保されるAudio Queue Bufferのバイト数です。“[[# | ||
+ | - 新しく確保されたAudio Queue Bufferが出力されます。バッファへのポインタはAudio Queueと共に使う独自構造体の中に置かれます。 | ||
+ | - '' | ||
+ | - キューに加えるAudio Queue Bufferを持つAudio Queue。 | ||
+ | - キューに加えるAudio Queue Buffer。 | ||
+ | - 録音におけるバッファのキュー追加では、本パラメータは使用しません。 | ||
+ | - 録音におけるバッファのキュー追加では、本パラメータは使用しません。 | ||
- | The AudioQueueAllocateBuffer function asks an audio queue to allocate an audio queue buffer. | + | ===== 録音 ===== |
- | The audio queue that performs the allocation and that will own the buffer. | + | リスト2-14で示されるように、これまでのコードの全てが録音のとてもシンプルな工程に繋がりました。 |
- | + | ||
- | The size, in bytes, for the new audio queue buffer being allocated. See “Write a Function to Derive Recording Audio Queue Buffer Size.” | + | |
- | + | ||
- | On output, the newly allocated audio queue buffer. The pointer to the buffer is placed in the custom structure you’re using with the audio queue. | + | |
- | + | ||
- | The AudioQueueEnqueueBuffer function adds an audio queue buffer to the end of a buffer queue. | + | |
- | + | ||
- | The audio queue whose buffer queue you are adding the buffer to. | + | |
- | + | ||
- | The audio queue buffer you are enqueuing. | + | |
- | + | ||
- | This parameter is unused when enqueuing a buffer for recording. | + | |
- | + | ||
- | This parameter is unused when enqueuing a buffer for recording. | + | |
- | + | ||
- | Record Audio | + | |
- | + | ||
- | All of the preceding code has led up to the very simple process of recording, as shown in Listing | + | |
- | + | ||
- | Listing 2-14 Recording audio | + | |
+ | **リスト 2-14** 録音 | ||
+ | <code c_mac> | ||
aqData.mCurrentPacket = 0; // 1 | aqData.mCurrentPacket = 0; // 1 | ||
- | |||
aqData.mIsRunning = true; // 2 | aqData.mIsRunning = true; // 2 | ||
- | |||
- | |||
AudioQueueStart ( // 3 | AudioQueueStart ( // 3 | ||
- | |||
aqData.mQueue, | aqData.mQueue, | ||
- | |||
NULL // 5 | NULL // 5 | ||
- | |||
); | ); | ||
- | + | // ユーザーインターフェーススレッドにおいてユーザーが録音を止めるまで待つ | |
- | // Wait, on user interface thread, until user stops the recording | + | |
AudioQueueStop ( // 6 | AudioQueueStop ( // 6 | ||
- | |||
aqData.mQueue, | aqData.mQueue, | ||
- | |||
true // 8 | true // 8 | ||
- | |||
); | ); | ||
- | |||
- | |||
aqData.mIsRunning = false; | aqData.mIsRunning = false; | ||
+ | </ | ||
- | Here’s how this code works: | + | コードの働きを見てみましょう: |
- | Initializes the packet index to 0 to begin recording at the start of the audio file. | + | - Audio Fileの先頭から記録するためにパケットインデックスを'' |
+ | - Audio Queueが実行中を表すフラグを独自構造体にセットします。このフラグは録音Audio Queueコールバックで使用されます。 | ||
+ | - '' | ||
+ | - 開始するAudio Queue。 | ||
+ | - '' | ||
+ | - '' | ||
+ | - 停止するAudio Queue。 | ||
+ | - '' | ||
+ | - Audio Queueが非実行中を示すフラグを独自構造体にセットします。 | ||
- | Sets a flag in the custom structure to indicate that the audio queue is running. This flag is used by the recording audio queue callback. | + | ===== 録音後の後始末 ===== |
- | The AudioQueueStart function starts the audio queue, on its own thread. | + | 録音が終わったら、Audio Queueを破棄しAudio Fileを閉じます。 |
- | + | リスト | |
- | The audio queue to start. | + | |
- | + | ||
- | Uses NULL to indicate that the audio queue should start recording immediately. | + | |
- | + | ||
- | The AudioQueueStop function stops and resets the recording audio queue. | + | |
- | + | ||
- | The audio queue to stop. | + | |
- | + | ||
- | Use true to use synchronous stopping. See “Audio Queue Control and State” for an explanation of synchronous and asynchronous stopping. | + | |
- | + | ||
- | Sets a flag in the custom structure to indicate that the audio queue is not running. | + | |
- | + | ||
- | Clean Up After Recording | + | |
- | + | ||
- | When you’re finished with recording, dispose of the audio queue and close the audio file. Listing 2-15 illustrates these steps. | + | |
- | + | ||
- | Listing | + | |
+ | **リスト 2-15** 録音後の後始末 | ||
+ | <code c_mac> | ||
AudioQueueDispose ( // 1 | AudioQueueDispose ( // 1 | ||
- | |||
aqData.mQueue, | aqData.mQueue, | ||
- | |||
true // 3 | true // 3 | ||
- | |||
); | ); | ||
- | |||
- | |||
AudioFileClose (aqData.mAudioFile); | AudioFileClose (aqData.mAudioFile); | ||
+ | </ | ||
- | Here’s how this code works: | + | コードの働きを見てみましょう: |
- | + | ||
- | The AudioQueueDispose function disposes of the audio queue and all of its resources, including its buffers. | + | |
- | + | ||
- | The audio queue you want to dispose of. | + | |
- | Use true to dispose of the audio queue synchronously (that is, immediately). | + | - '' |
+ | - 破棄したいAudio Queue。 | ||
+ | - '' | ||
+ | - 記録に使ったAudio Fileを閉じます。'' | ||
- | Closes the audio file that was used for recording. The AudioFileClose function is declared in the AudioFile.h header file. |