2017-01-05 8 views
1

AVCaptureDeviceFormatからオーディオの説明を取得できます。CMAudioFormatDescriptionでサンプルレートとチャンネルあたりのビット数を得るには

let formats = device.formats 
for format in formats { 
print(format.formatDescription) 
} 

しかし、mSampleRateプロパティとmBitsPerChannelプロパティに直接アクセスしたいと思います。

CMAudioFormatDescription 0x60000010b880 [0x7fffadb29d80] { 

    mediaType:'soun' 
    mediaSubType:'lpcm' 
    mediaSpecific: { 
     ASBD: { 
      mSampleRate: 44100.000000 
      mFormatID: 'lpcm' 
      mFormatFlags: 0x9 
      mBytesPerPacket: 8 
      mFramesPerPacket: 1 
      mBytesPerFrame: 8 
      mChannelsPerFrame: 2 
      mBitsPerChannel: 32  } 
     cookie: {(null)} 
     ACL: {Stereo (L R)} 
     FormatList Array: {(null)} 
    } 
    extensions: {(null)} 
} 

どうすればよいですか? 私はAudioToolBoxフレームワークのAudioFormatGetProperty()を調べていますが、迷子になっています。 すべての助力が大変感謝しています。

答えて

1

あなたはフォーマットの記述からAudioStreamBasicDescriptionを得ることができ、あなたが必要とするデータとは:

let asbd = CMAudioFormatDescriptionGetStreamBasicDescription(format.formatDescription) 

if let asbd = asbd?.pointee { 
    print("Sample rate: \(asbd.mSampleRate), bits per channel: \(asbd.mBitsPerChannel)") 
} 
+0

これは完璧です、ありがとうございました。 –

+0

あなたは大歓迎です! –

関連する問題