> I've set up a simple audio recorder, but I'm having trouble recording to a
> file after I reopen the file. As long as I have the audio queue running, I
> can stop and start the queue, and audio is appended perfectly to the file --
> it plays back just fine.
> The problem arises when I dispose the queue and close the file, then reopen
> it and try to resume recording at the last packet:
>
> AudioFileOpenURL((CFURLRef)audioFileURL, kAudioFileReadWritePermission,
> kAudioFileCAFType, &audioFileID);
>
> UInt32 propertySize = sizeof(currentPacket);
>
> AudioFileGetProperty(audioFileID, kAudioFilePropertyAudioDataPacketCount,
> &propertySize, ¤tPacket);
>
> First, I got an error stating the file is not optimized. That seemed
> reasonable, so I added this line:
>
> AudioFileOptimize(audioFileID);
>
> Now, I'm error free and can successfully write packets! My callback looks
> like this:
>
> static void PSAudioRecorder_Callback(void *audioData, AudioQueueRef
> audioQueue, AudioQueueBufferRef audioBuffer, const AudioTimeStamp *time,
> UInt32 numPackets, const AudioStreamPacketDescription *packetDescription) {
>
> PSAudioRecorder *recorder = (PSAudioRecorder *)audioData;
>
> if (numPackets > 0) {
>
> AudioFileWritePackets(recorder.audioFileID, FALSE,
> audioBuffer->mAudioDataByteSize, packetDescription, recorder.currentPacket,
> &numPackets, audioBuffer->mAudioData);
>
> recorder.currentPacket += numPackets;
>
> }
>
> if ([recorder isRunning]) {
>
> AudioQueueEnqueueBuffer(audioQueue, audioBuffer, 0, NULL);
>
> }
>
> }
>
> As I'm recording I can monitor the file size and see that the file is indeed
> growing in size. Audio data is being appended.
>
> However, when I stop recording, and then try to play back the file, the
> appended recording data won't play.
>
> It's as if the header information is not being updated correctly so the
> player stops prematurely.
>
> I don't understand why this happens because every time I stop the queue, I
> re-copy the magic cookie (which I assume is an abstraction for header
> information).
>
> I'm truly at a loss here. The only other option I can think of at this point
> is each time I want to append audio, create a new file, copy all the packets
> from the original file, write them to the new file, then append the new
> recorded packets. Yuck.
>
> What am I missing?
>
> Thanks,
>
> Donald
>
> _______________________________________________