差分
このページの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 [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: | ||
コードの働きを見てみましょう: | コードの働きを見てみましょう: | ||
- | - < | + | - '' |
- | - 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. | + | - 録音におけるバッファのキュー追加では、本パラメータは使用しません。 |
===== 録音 ===== | ===== 録音 ===== | ||
行 543: | 行 547: | ||
コードの働きを見てみましょう: | コードの働きを見てみましょう: | ||
- | - Audio Fileの先頭から記録するためにパケットインデックスを< | + | - Audio Fileの先頭から記録するためにパケットインデックスを'' |
- Audio Queueが実行中を表すフラグを独自構造体にセットします。このフラグは録音Audio Queueコールバックで使用されます。 | - Audio Queueが実行中を表すフラグを独自構造体にセットします。このフラグは録音Audio Queueコールバックで使用されます。 | ||
- | - < | + | - '' |
- 開始するAudio Queue。 | - 開始するAudio Queue。 | ||
- | - < | + | - '' |
- | - < | + | - '' |
- 停止するAudio Queue。 | - 停止するAudio Queue。 | ||
- | - < | + | - '' |
- Audio Queueが非実行中を示すフラグを独自構造体にセットします。 | - Audio Queueが非実行中を示すフラグを独自構造体にセットします。 | ||
行 570: | 行 574: | ||
コードの働きを見てみましょう: | コードの働きを見てみましょう: | ||
- | - < | + | - '' |
- 破棄したいAudio Queue。 | - 破棄したいAudio Queue。 | ||
- | - < | + | - '' |
- | - 記録に使ったAudio Fileを閉じます。< | + | - 記録に使ったAudio Fileを閉じます。'' |