差分
このページの2つのバージョン間の差分を表示します。
両方とも前のリビジョン 前のリビジョン 次のリビジョン | 前のリビジョン 次のリビジョン 両方とも次のリビジョン | ||
translation:adc:audio:audio_queue_services_programming_guide:0300_recordingaudio [2014-09-01 20:37] Decomo |
translation:adc:audio:audio_queue_services_programming_guide:0300_recordingaudio [2014-09-08 19:29] Decomo [Audio Queue Bufferセットの準備] |
||
---|---|---|---|
行 310: | 行 310: | ||
- 関数の成否を返します。 | - 関数の成否を返します。 | ||
- | ===== 録音用音声フォーマットの構成 ===== | + | ===== 録音音声フォーマットの構成 ===== |
本項ではAudio Queueの音声データ形式の構成方法を説明します。 | 本項では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: | ||
コードの働きを見てみましょう: | コードの働きを見てみましょう: | ||
- | - < | + | - < |
- | - 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 | + | - 音声データタイプをリニアPCMとして定義します。利用可能なデータ形式の完全なリストは// |
- | - Defines the audio data format type as linear | + | - サンプリング周波数を44.1kHzとします。 |
- | - Defines the sample rate as 44.1 kHz. | + | - チャンネル数は2とします。 |
- | - Defines the number of channels as 2. | + | - チャンネルあたりのビット深度は16とします。 |
- | - Defines the bit depth per channel as 16. | + | - パケットあたりのバイト数とフレームあたりのバイト数は4とします(2チャンネル×サンプルあたり2バイト)。 |
- | - 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). | + | - パケットあたりのフレーム数は1とします。 |
- | - Defines the number of frames per packet as 1. | + | - ファイルタイプはAIFFとします。利用可能なファイルタイプの完全なリストは< |
- | - Defines the file type as AIFF. See the audio file types enumeration in the AudioFile.h | + | - 特定のファイルタイプで必要となるフォーマットフラグを設定します。 |
- | - Sets the format flags needed for the specified file type. | + | |
===== 録音Audio Queueの生成 ===== | ===== 録音Audio Queueの生成 ===== | ||
- | Now, with the recording callback and audio data format set up, you create and configure an audio queue for recording. | + | それでは、録音コールバックと音声データ形式を設定して、録音Audio Queueの生成と設定をします。 |
==== 録音Audio Queueを生成する ==== | ==== 録音Audio Queueを生成する ==== | ||
- | Listing | + | リスト2-9は録音Audio Queueの作り方を示したものです。 |
- | + | < | |
- | Listing 2-9 Creating a recording audio queue | + | |
+ | **リスト 2-9** 録音Audio Queueの生成 | ||
<code c_mac> | <code c_mac> | ||
AudioQueueNewInput ( // 1 | AudioQueueNewInput ( // 1 | ||
行 386: | 行 385: | ||
コードの働きを見てみましょう: | コードの働きを見てみましょう: | ||
- | - The AudioQueueNewInput function creates a new recording audio queue. | + | - < |
- | - The audio data format to use for the recording. See “Set Up an Audio Format for Recording.” | + | - 録音に使う音声データ形式です。“[[# |
- | - The callback function to use with the recording audio queue. See “Write a Recording | + | - 録音Audio Queueが使うコールバック関数です。“[[#録音Audio Queueコールバックの実装]]”をご覧下さい。 |
- | - The custom data structure for the recording audio queue. See “Define a Custom Structure to Manage State.” | + | - 録音Audio Queueの独自データ構造体です。“[[# |
- | - 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 | + | - コールバック呼び出しの実行ループモードです。通常、ここには< |
- | - Reserved. Must be 0. | + | - 将来拡張用です。< |
- | - On output, the newly allocated recording audio queue. | + | - 新たに確保された録音Audio Queueが出力されます。 |
==== Audio Queueから完全な音声形式を取得する ==== | ==== Audio Queueから完全な音声形式を取得する ==== | ||
- | When the audio queue came into existence (see “Creating a Recording | + | Audio Queueの実体が出来ると(“[[#録音Audio Queueの生成]]”をご覧下さい)、Audio Queueは特に圧縮フォーマットにおいて、あなたが持っているものより完全に< |
+ | 完全なフォーマット記述を取得するには、リスト2-10で示すように< | ||
+ | 記録先のAudio Fileを作る際は、その完全な音声フォーマットをしようします(“[[#Audio Fileの生成]]”をご覧下さい)。 | ||
- | Listing | + | **リスト |
<code c_mac> | <code c_mac> | ||
行 407: | 行 408: | ||
aqData.mQueue, | aqData.mQueue, | ||
kAudioQueueProperty_StreamDescription, | kAudioQueueProperty_StreamDescription, | ||
- | // in Mac OS X, instead use | + | // Mac OS Xでは代わりに↓を使ってください |
// kAudioConverterCurrentInputStreamDescription | // kAudioConverterCurrentInputStreamDescription | ||
& | & | ||
行 415: | 行 416: | ||
コードの働きを見てみましょう: | コードの働きを見てみましょう: | ||
- | - Gets an expected property value size to use when querying the audio queue about its audio data format. | + | - Audio Queueに音声データ形式を問い合わせる時に使う、プロパティ値の期待サイズを得ます。 |
- | - The AudioQueueGetProperty | + | - < |
- | - The audio queue to obtain the audio data format from. | + | - 音声データ形式を取得するAudio Queueです。 |
- | - The property | + | - Audio Queueのデータ形式値を得るためのプロパティIDです。 |
- | - On output, the full audio data format, in the form of an AudioStreamBasicDescription | + | - 出力で、Audio Queueから得られた< |
- | - On input, the expected size of the AudioStreamBasicDescription | + | - 入力では、< |
===== Audio Fileの生成 ===== | ===== 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 | + | 生成と設定が行われたAudio Queueを使って、リスト2-11のように録音データを保存するAudio Fileを生成します。 |
+ | Audio Fileは、前述のAudio Queueの独自構造体に格納されたデータ形式とファイル形式仕様を使います。 | ||
- | Listing | + | **リスト |
<code c_mac> | <code c_mac> | ||
行 448: | 行 450: | ||
コードの働きを見てみましょう: | コードの働きを見てみましょう: | ||
- | - The CFURLCreateFromFileSystemRepresentation function, declared in the CFURL.h | + | - < |
- | - Use NULL (or kCFAllocatorDefault) | + | - < |
- | - The file-system path you want to convert to a CFURL object. In production code, you would typically obtain a value for filePath | + | - < |
- | - The number of bytes in the file-system path. | + | - ファイルシステムパスのバイト数です。 |
- | - A value of false indicates that filePath | + | - < |
- | - The AudioFileCreateWithURL function, from the AudioFile.h | + | - < |
- | - 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. | + | - 新規音声ファイルの作成、もしくは既存ファイルの初期化の対象となるURLです。URLは手順1の[[https:// |
- | - 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 | + | - < |
- | - Erases the file, in the case that the file already exists. | + | - ファイルが既に存在していた場合、そのファイルを消します。 |
- | - On output, an audio file object | + | - 出力で、記録先の音声ファイルを表す(< |
===== Audio Queue Bufferサイズの設定 ===== | ===== Audio Queue Bufferサイズの設定 ===== | ||
- | Before you prepare a set of audio queue buffers that you’ll use while recording, you make use of the DeriveBufferSize | + | 録音中に使うAudio Queue Bufferセットを準備する前に、先に書いた< |
+ | このサイズを使用する録音Audio Queueのサイズに割り当てます。 | ||
+ | リスト2-12がその様子を示します: | ||
- | Listing | + | **リスト |
<code c_mac> | <code c_mac> | ||
行 477: | 行 481: | ||
コードの働きを見てみましょう: | コードの働きを見てみましょう: | ||
- | - The DeriveBufferSize function, described in “Write a Function to Derive Recording | + | - “[[#録音Audio Queue Bufferサイズを計算する関数の実装]]”で解説した< |
- | - The audio queue that you’re setting buffer size for. | + | - バッファサイズを設定するAudio Queueです。 |
- | - The audio data format for the file you are recording. See “Set Up an Audio Format for Recording.” | + | - 記録するファイルの音声データ形式です。“[[# |
- | - The number of seconds of audio that each audio queue buffer should hold. One half second, as set here, is typically a good choice. | + | - 各Audio Queue Bufferが保持する音声の秒数です。通常、ここで設定している0.5秒が良い選択です。 |
- | - On output, the size for each audio queue buffer, in bytes. This value is placed in the custom structure for the audio queue. | + | - 出力で、各Audio Queue Bufferサイズがバイト数で返ります。この値はAudio Queueの独自構造体の中に置かれます。 |
===== Audio Queue Bufferセットの準備 ===== | ===== Audio Queue Bufferセットの準備 ===== | ||
- | You now ask the audio queue that you’ve created | + | それでは、(“[[#録音Audio Queueの生成]]”で)生成したAudio Queueに、Audio Queue Bufferセットを準備するように命令します。 |
- | + | リスト | |
- | Listing | + | |
+ | **リスト 2-13** Audio Queue Bufferセットの準備 | ||
<code c_mac> | <code c_mac> | ||
for (int i = 0; i < kNumberBuffers; | for (int i = 0; i < kNumberBuffers; | ||
行 508: | 行 512: | ||
コードの働きを見てみましょう: | コードの働きを見てみましょう: | ||
- | - Iterates to allocate and enqueue each audio queue buffer. | + | - 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. | + | - バッファを確保し所持するAudio Queueです。 |
- | - The size, in bytes, for the new audio queue buffer being allocated. See “Write a Function to Derive Recording | + | - 新しく確保されるAudio Queue Bufferのバイト数です。“[[#録音Audio Queue Bufferサイズを計算する関数の実装]]”をご覧下さい。 |
- | - 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. | + | - 新しく確保されたAudio Queue Bufferが出力されます。バッファへのポインタは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. | + | - キューに加えるAudio Queue Bufferを持つAudio Queue。 |
- | - The audio queue buffer you are enqueuing. | + | - キューに加えるAudio Queue Buffer。 |
- | - This parameter is unused when enqueuing a buffer for recording. | + | - 録音におけるバッファのキュー追加では、本パラメータは使用しません。 |
- | - This parameter is unused when enqueuing a buffer for recording. | + | - 録音におけるバッファのキュー追加では、本パラメータは使用しません。 |
===== 録音 ===== | ===== 録音 ===== |