This actually works. I'm using it in an audio recording/looping app where I need to read the data from arbitrary locations while it's being recorded. I haven't tested it with encoded audio, but it works great for LPCM.
For writing: AudioFileWritePackets takes an offset argument so there is no "seeking". AudioFileID audioFile; AudioFileCreateWithURL(url, kAudioFileCAFType, &asbd, kAudioFileFlags_EraseFile, &audioFile); AudioFileWritePackets(audioFile, 0, samplesToWrite * sampleSize, NULL, offset, &samplesToWrite, inBuffer); For reading you use the same AudioFileID to create your ExtAudioFileRef: ExtAudioFileRef extAudioFile; ExtAudioFileWrapAudioFileID(audioFile, 0, &extAudioFile); ExtAudioFileSeek(extAudioFile,readStartSample); ExtAudioFileRead(extAudioFile, ioNumberFrames, bufferListOut); It don't know if the CAF file type is necessary or not, but it's a good starting point. On Fri, Jul 24, 2015 at 2:49 PM, Matthew Pease <[email protected]> wrote: > Is this really supported? I couldn't find this documented anywhere (I > know... what a surprise.) > > The thing is, it is hard to know the right way to do it. When I seek in a > file that is open for writing, it seems to work just fine. I wish Apple > would elaborate on what is wrong with seeking in a file open for writing > and whats an alternative that would actually work. > > Thanks- > Matt > > On Fri, Jul 24, 2015 at 8:43 PM, Dave O'Neill <[email protected]> wrote: > >> One way to do it is to create an AudioFileID open for reading and writing >> using the Audio File Services Reference >> https://developer.apple.com/library/mac/documentation/MusicAudio/Reference/AudioFileConvertRef/ >> Then you create a ExtAudioFileID for reading only using >> ExtAudioFileWrapAudioFileID. This actually works, but writing to Audio file >> isn't that straightforward if it's not LPCM. >> >> On Fri, Jul 24, 2015 at 9:44 AM, Matthew Pease <[email protected]> wrote: >> >>> Hi all - >>> >>> I've searched for a previous answer to this question, but did not find >>> one. >>> >>> In my IOS app, I record a stream to a file. I then want to provide >>> playback access to that file starting from any offset. The user can listen >>> to any part of that file by dragging a slider. >>> >>> The problem is that the file is continuously growing while the new >>> stream data arrives & is appended to the file. >>> >>> ExtAudioFileSeek says that its behavior is undefined for files that are >>> open for writing. Also when I play the file back, I might move past a >>> point which was the end of the file when the file was originally opened. >>> >>> I suppose one way I could do it would be to continuously close & open >>> the file. open to write, then close it. And then open it again to read >>> the next part of the stream. I can make the file an uncompressed format so >>> that seeking within the file will be fast. >>> >>> Does this sound like a good plan? Any other possibilties? >>> >>> >>> Thank you- >>> Matt >>> >>> _______________________________________________ >>> Do not post admin requests to the list. They will be ignored. >>> Coreaudio-api mailing list ([email protected]) >>> Help/Unsubscribe/Update your Subscription: >>> >>> https://lists.apple.com/mailman/options/coreaudio-api/oneill707%40gmail.com >>> >>> This email sent to [email protected] >>> >> >> >
_______________________________________________ Do not post admin requests to the list. They will be ignored. Coreaudio-api mailing list ([email protected]) Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/coreaudio-api/archive%40mail-archive.com This email sent to [email protected]
