Created
July 19, 2019 01:37
-
-
Save SunXiaoShan/d40a90a03f46a34e4f459aeebe4fbbb0 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
// Step 2: Calculate the buffer size | |
UInt32 size = sizeof(maxPacketSize); | |
AudioFileGetProperty( | |
audioFileID, | |
kAudioFilePropertyPacketSizeUpperBound, | |
&size, | |
&maxPacketSize); | |
if (status != noErr) NSLog(@"kAudioFilePropertyPacketSizeUpperBound failed %d", status); | |
if (dataFormat.mFramesPerPacket != 0) { | |
Float64 numPacketsPersecond = dataFormat.mSampleRate / dataFormat.mFramesPerPacket; | |
outBufferSize = numPacketsPersecond * maxPacketSize; | |
} else { | |
outBufferSize = (maxBufferSize > maxPacketSize) ? maxBufferSize : maxPacketSize; | |
} | |
if (outBufferSize > maxBufferSize && | |
outBufferSize > maxPacketSize) { | |
outBufferSize = maxBufferSize; | |
} else { | |
if (outBufferSize < minBufferSize) { | |
outBufferSize = minBufferSize; | |
} | |
} | |
// Step 3: Calculate the package count | |
numPacketsToRead = outBufferSize / maxPacketSize; | |
// Step 4: Alloc AudioStreamPacketDescription buffers | |
packetDescs = (AudioStreamPacketDescription *)malloc(numPacketsToRead * sizeof(AudioStreamPacketDescription)); | |
// Step 5: Reset the packet index | |
packetIndex = 0; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment