I just don't get AudioFileReadPackets
- by Eric Christensen
I've tried to write the smallest chunk of code to narrow down a problem. It's now just a few lines and it doesn't work, which makes it pretty clear that I have a fundamental misunderstanding of how to use AudioFileReadPackets. I've read the docs and other examples online, and apparently I'm just not getting. Could you explain it to me?
Here's what this block should do: I've previously opened a file. I want to read just one packet - the first one of the file - and then print it. But it crashes on the AudioFileReadPackets line:
AudioFileID mAudioFile2;
AudioFileOpenURL (audioFileURL, 0x01, 0, &mAudioFile2);
UInt32 *audioData2 = (UInt32 *)malloc(sizeof(UInt32) * 1);
AudioFileReadPackets(mAudioFile2, false, NULL, NULL, 0, (UInt32*)1, audioData2);
NSLog(@"first packet:%i",audioData2[0]);
(For clarity, I've stripped out all error handling.)
It's the AFRP line that crashes out.
(I understand that the third and fourth argument are useful, and in my "real" code, I use them, but they're not required, right? So NULL in this case should work, right?) So then what's going on?
Any guidance would be much appreciated.
Thanks.