Re: Appended audio packets won't play back (IMA4)
Re: Appended audio packets won't play back (IMA4)
- Subject: Re: Appended audio packets won't play back (IMA4)
- From: tahome izwah <email@hidden>
- Date: Tue, 04 Oct 2011 06:59:25 +0200
I'm not sure if appending works reliably with all types of encoded
files... what format is your CAF file in? Did you try using PCM format
to see if that works?
Also are you sure you're closing the file when you're done with it?
For some operations and formats the file structure is updated on
close, so you won't have access to the data unless you close the file
and dispose its refID.
The magic cookie is not the same as the file regular header. Apple
hints that it contains additional information required to decompress
the file, see http://developer.apple.com/library/mac/#qa/qa1318/_index.html
--th
2011/10/3 Donald Ness <email@hidden>:
> 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
>
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Coreaudio-api mailing list (email@hidden)
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
>
>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden