Skip to content

Instantly share code, notes, and snippets.

@SunXiaoShan
Created July 19, 2019 01:32
Show Gist options
  • Save SunXiaoShan/6e4be38deb911d6b5d7ee956c57772c1 to your computer and use it in GitHub Desktop.
Save SunXiaoShan/6e4be38deb911d6b5d7ee956c57772c1 to your computer and use it in GitHub Desktop.
- (AudioStreamBasicDescription)parseAudioFileData:(AudioFileID)audioFileID
error:(NSError **)error {
AudioStreamBasicDescription buffDataFormat;
UInt32 formatSize = sizeof(AudioStreamBasicDescription);
OSStatus status = AudioFileGetProperty(audioFileID, kAudioFilePropertyDataFormat, &formatSize, &buffDataFormat);
if (status != noErr) {
NSLog(@"parseAudioFileData failed %d", status);
*error = [NSError errorWithDomain:@"parse data format failed" code:-100 userInfo:nil];
}
return buffDataFormat;
}
- (OSStatus)parseAudioListFileData:(AudioFileID)audioFileID {
UInt32 formatListSize = 0;
OSStatus status = AudioFileGetPropertyInfo(audioFileID, kAudioFilePropertyFormatList, &formatListSize, NULL);
if (status != noErr) NSLog(@"AudioFileGetPropertyInfo data format failed");
if (status == noErr) {
AudioFormatListItem *formatList = (AudioFormatListItem *)malloc(formatListSize);
status = AudioFileGetProperty(audioFileID, kAudioFilePropertyFormatList, &formatListSize, formatList);
if (status == noErr) {
for (int i = 0; i * sizeof(AudioFormatListItem) < formatListSize; i += sizeof(AudioFormatListItem)) {
AudioStreamBasicDescription pasbd = formatList[i].mASBD;
NSLog(@"mFormatID = %d", (signed int)pasbd.mFormatID);
NSLog(@"mFormatFlags = %d", (signed int)pasbd.mFormatFlags);
NSLog(@"mSampleRate = %ld", (signed long int)pasbd.mSampleRate);
NSLog(@"mBitsPerChannel = %d", (signed int)pasbd.mBitsPerChannel);
NSLog(@"mBytesPerFrame = %d", (signed int)pasbd.mBytesPerFrame);
NSLog(@"mBytesPerPacket = %d", (signed int)pasbd.mBytesPerPacket);
NSLog(@"mChannelsPerFrame = %d", (signed int)pasbd.mChannelsPerFrame);
NSLog(@"mFramesPerPacket = %d", (signed int)pasbd.mFramesPerPacket);
NSLog(@"mReserved = %d", (signed int)pasbd.mReserved);
}
}
free(formatList);
}
return status;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment