Skip to content

Instantly share code, notes, and snippets.

@onevcat
Created April 12, 2017 01:08
Show Gist options
  • Save onevcat/cc72e6946e27fe9bec0edfd6adc5f9c1 to your computer and use it in GitHub Desktop.
Save onevcat/cc72e6946e27fe9bec0edfd6adc5f9c1 to your computer and use it in GitHub Desktop.
var status: OSStatus
let readOrWrite = kAudioFileGlobalInfo_ReadableTypes
var propertySize: UInt32 = 0
status = AudioFileGetGlobalInfoSize(readOrWrite,
0,
nil,
&propertySize)
print(status)
print(propertySize)
let typesAddress = UnsafeMutablePointer<AudioStreamBasicDescription>.allocate(capacity: Int(propertySize))
status = AudioFileGetGlobalInfo(readOrWrite,
0,
nil,
&propertySize,
typesAddress)
let count = Int(propertySize) / MemoryLayout<AudioStreamBasicDescription>.size
for i in 0..<count {
var format4cc = typesAddress[i].mFormatID.bigEndian
withUnsafePointer(to: &format4cc) {ptr in
print(String(format: "%d: mFormatID: %4.4s, mFormatFlags: %d, mBitsPerChannel: %d", arguments: [i, ptr, typesAddress[i].mFormatFlags, typesAddress[i].mBitsPerChannel]))
}
}
typesAddress.deallocate(capacity: Int(propertySize))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment