2017-01-05 1 views
1

Je suis en mesure d'obtenir la description audio de AVCaptureDeviceFormat.Comment puis-je obtenir le taux d'échantillonnage et bits par canal sur une CMAudioFormatDescription

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

Mais voudrait obtenir directement à la propriété mSampleRate et 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)} 
} 

Comment est-ce que je peux y arriver? J'ai regardé dans le AudioFormatGetProperty() dans le cadre AudioToolBox, mais je me perds. Toute l'aide grandement appréciée.

Répondre

1

Vous pouvez obtenir le AudioStreamBasicDescription de la description du format et de les données dont vous avez besoin:

let asbd = CMAudioFormatDescriptionGetStreamBasicDescription(format.formatDescription) 

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

C'est parfait, merci. –

+0

De rien! –