2012-03-19 5 views
0

私は音楽をプレイするプレイヤーを書いています。私は以下のようなコードを参照してください。このキュープロパティ(iOSオーディオキュー)の意味は?

AudioFileGetPropertyInfo(audioFile, 
         kAudioFilePropertyMagicCookieData, &size, nil); 

if (size > 0) { 
    cookie = malloc(sizeof(char) * size); 
    AudioFileGetProperty(audioFile, 
         kAudioFilePropertyMagicCookieData, &size, cookie); 
    AudioQueueSetProperty(aduioQueue, 
          kAudioQueueProperty_MagicCookie, cookie, size); 
    free(cookie); 
} 

私はなぜAudioQueuePropertyを設定する方法がわからない、とkAudioQueueProperty_MagicCookie程度手段は何ですか?私はドキュメンテーションから助けを見つけることができません。 誰が問題をスローする方向を与えることができます。

答えて

1

「マジッククッキー」は、ファイルの先頭にユニークな一連のバイトで構成されたファイルタイプシグネチャで、ファイル形式を示します。オーディオキューフレームワークは、この情報を使用して、(ファイル名の拡張子を使用または信頼する代わりに)ファイルストリームからオーディオ情報をデコードまたは抽出する方法を決定します。投稿したコードは、ファイルからこのバイトセットを読み取り、それをクッキーとしてオーディオキューに渡します。 (例えば、代わりにPCMサンプルとして解釈されるのは間違いでしょう)。

+0

ありがとうございました。私はkAudioQueueProperty_MagicCookieについてのドキュメントを見つける。 「再生または録音するオーディオフォーマットに魔法のクッキーが必要な場合は、バッファをエンキューする前にこのプロパティの値を設定する必要があります。」...私のアプリでは、上記のコードをクリアし、サウンドは次のようになります。 OK。私の質問は、オーディオキューはファイル形式を推定する能力があるということですか? – Henry

1

実際には、マジッククッキーはエンコーダーに関するいくつかの情報を保持しています。最も有用な項目は「Maximum Bit Rate」と「Average Bit Rate」です。特にAudioFileMPEG4Typeのような圧縮形式です。この特定のタイプのマジッククッキーは、MPEG-4データファイルの "esds"ボックスと同じです。 VERSバイト8+

http://xhelmboyx.tripod.com/formats/mp4-layout.txt


の位置は:正確なビット設定を見つけることができます。 2 ESディスクリプタボックス は=符号なしlong +長いASCIIテキスト文字列 'ESDS' オフセット - ISO/IEC 14496-10 AVC規格にエンコードされた場合は、その後、必要に応じて使用します。 = unsigned long型+オフセット長いASCIIテキスト文字列 'm4ds'

kAudioFilePropertyMagicCookieDataから来
   -> 4 bytes version/flags = 8-bit hex version + 24-bit hex flags 
        (current = 0) 

       -> 1 byte ES descriptor type tag = 8-bit hex value 0x03 
       -> 3 bytes extended descriptor type tag string = 3 * 8-bit hex value 
        - types are Start = 0x80 ; End = 0xFE 
        - NOTE: the extended start tags may be left out 
       -> 1 byte descriptor type length = 8-bit unsigned length 

        -> 2 bytes ES ID = 16-bit unsigned value 
        -> 1 byte stream priority = 8-bit unsigned value 
        - Defaults to 16 and ranges from 0 through to 31 

        -> 1 byte decoder config descriptor type tag = 8-bit hex value 0x04 
        -> 3 bytes extended descriptor type tag string = 3 * 8-bit hex value 
         - types are Start = 0x80 ; End = 0xFE 
         - NOTE: the extended start tags may be left out 
        -> 1 byte descriptor type length = 8-bit unsigned length 

         -> 1 byte object type ID = 8-bit unsigned value 
         - type IDs are system v1 = 1 ; system v2 = 2 
         - type IDs are MPEG-4 video = 32 ; MPEG-4 AVC SPS = 33 
         - type IDs are MPEG-4 AVC PPS = 34 ; MPEG-4 audio = 64 
         - type IDs are MPEG-2 simple video = 96 
         - type IDs are MPEG-2 main video = 97 
         - type IDs are MPEG-2 SNR video = 98 
         - type IDs are MPEG-2 spatial video = 99 
         - type IDs are MPEG-2 high video = 100 
         - type IDs are MPEG-2 4:2:2 video = 101 
         - type IDs are MPEG-4 ADTS main = 102 
         - type IDs are MPEG-4 ADTS Low Complexity = 103 
         - type IDs are MPEG-4 ADTS Scalable Sampling Rate = 104 
         - type IDs are MPEG-2 ADTS = 105 ; MPEG-1 video = 106 
         - type IDs are MPEG-1 ADTS = 107 ; JPEG video = 108 
         - type IDs are private audio = 192 ; private video = 208 
         - type IDs are 16-bit PCM LE audio = 224 ; vorbis audio = 225 
         - type IDs are dolby v3 (AC3) audio = 226 ; alaw audio = 227 
         - type IDs are mulaw audio = 228 ; G723 ADPCM audio = 229 
         - type IDs are 16-bit PCM Big Endian audio = 230 
         - type IDs are Y'CbCr 4:2:0 (YV12) video = 240 ; H264 video = 241 
         - type IDs are H263 video = 242 ; H261 video = 243 
         -> 6 bits stream type = 3/4 byte hex value 
         - type IDs are object descript. = 1 ; clock ref. = 2 
         - type IDs are scene descript. = 4 ; visual = 4 
         - type IDs are audio = 5 ; MPEG-7 = 6 ; IPMP = 7 
         - type IDs are OCI = 8 ; MPEG Java = 9 
         - type IDs are user private = 32 
         -> 1 bit upstream flag = 1/8 byte hex value 
         -> 1 bit reserved flag = 1/8 byte hex value set to 1 
         -> 3 bytes buffer size = 24-bit unsigned value 
         -> 4 bytes maximum bit rate = 32-bit unsigned value 
         -> 4 bytes average bit rate = 32-bit unsigned value 

         -> 1 byte decoder specific descriptor type tag 
          = 8-bit hex value 0x05 
         -> 3 bytes extended descriptor type tag string 
          = 3 * 8-bit hex value 
          - types are Start = 0x80 ; End = 0xFE 
          - NOTE: the extended start tags may be left out 
         -> 1 byte descriptor type length 
          = 8-bit unsigned length 

          -> ES header start codes = hex dump 

        -> 1 byte SL config descriptor type tag = 8-bit hex value 0x06 
        -> 3 bytes extended descriptor type tag string = 3 * 8-bit hex value 
         - types are Start = 0x80 ; End = 0xFE 
         - NOTE: the extended start tags may be left out 
        -> 1 byte descriptor type length = 8-bit unsigned length 

         -> 1 byte SL value = 8-bit hex value set to 0x02 

マジッククッキーは、(ちょうどマップに記載された第1の4つのバイトを無視し、残りはクッキーを魔術ために完全一致となります)。

サンプルマジッククッキーをES記述子から始まります似ているだろうこの: - > 0XFA00(または64,000)で22オフセットされ 平均ビットレート -

03 80 80 80 22 00 00 00 04 80 80 80 14 40 15 00 18 00 00 00 FA 00 00 00 FA 00 05 80 80 80 02 12 08 06 80 80 80 01 02 

最大ビットレートは、18オフセットされる> 0XFA00(または64000)

をApple社のドキュメントによると、マジッククッキーが、読み書きが可能ですが、ファイルを作成または変換する前にビットレートを変更する機会はありませんでした。

誰かを助ける希望。