Created
July 19, 2019 01:32
-
-
Save SunXiaoShan/6e4be38deb911d6b5d7ee956c57772c1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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