Avfoundation 如何获得采样率&;CMAudioFormatDescription上每个通道的位

Avfoundation 如何获得采样率&;CMAudioFormatDescription上每个通道的位,avfoundation,core-audio,avcapturedevice,Avfoundation,Core Audio,Avcapturedevice,我可以从AVCaptureDeviceFormat获取音频描述 let formats = device.formats for format in formats { print(format.formatDescription) } 但希望直接访问mSampleRate和mBitsPerChannel属性 CMAudioFormatDescription 0x60000010b880 [0x7fffadb29d80] { mediaType:'soun' mediaSu

我可以从AVCaptureDeviceFormat获取音频描述

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(),但是我迷路了。
非常感谢您的帮助。

您可以从格式说明中获取
AudioStreamBasicDescription
,并从中获取所需的数据:

let asbd = CMAudioFormatDescriptionGetStreamBasicDescription(format.formatDescription)

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