Skip to content

Instantly share code, notes, and snippets.

@SunXiaoShan
Last active July 19, 2019 01:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SunXiaoShan/75f83728b19621e2075046427254ead2 to your computer and use it in GitHub Desktop.
Save SunXiaoShan/75f83728b19621e2075046427254ead2 to your computer and use it in GitHub Desktop.
// Step 1: load audio data
// If the packetIndex is out of range, the ioNumPackets will be 0
UInt32 ioNumBytes = outBufferSize;
UInt32 ioNumPackets = numPacketsToRead;
status = AudioFileReadPacketData(
_audioFile,
NO,
&ioNumBytes,
packetDescs,
packetIndex,
&ioNumPackets,
audioQueueBuffer->mAudioData
);
if (status != noErr) NSLog(@"AudioQueueSetParameter failed %d", status);
// Step 2: prevent load audio data failed
if (ioNumPackets <= 0) {
return;
}
// Step 3: re-assign the data size
audioQueueBuffer->mAudioDataByteSize = ioNumBytes;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment