2

I am trying to write a lowish level audio writer with the AudioFile & ExtAudioFile APIs. I am creating a new audio file with AudioFileInitializeWithCallbacks but it appears that this needs read & get size callbacks implemented. Why can't this just accept a single write callback and trust that the data has been written sucessfully.

What if I am writing to a stream which I can not seek into such as a CD or a network socket?

Surely this should just continually push data to the write callback and it is my responsibility to write this data where needed returning an error code if the operation didn't succeed.

The docs for AudioFile_SetSizeProc and AudioFile_WriteProc appear to be incorrect as they both talk about read operations "inPosition An offset into the data from which to read.", "@result The callback should return the size of the data.".

At the moment I have got past this by only writing to a file but I get a kExtAudioFileError_InvalidOperationOrder after the first write procedure. What does this mean? There are no comments in the docs about it.

Any pointers or help would be much appriciated.

dave96
  • 43
  • 2
  • Why are you using this callback-based API if you don't want callbacks? – hotpaw2 Jun 16 '12 at 16:32
  • 2
    Because the other option AudioFileCreateWithURL takes a CFURLRef which points to a physical file. I need to be able to write to any sort of stream so need the AudioFileInitializeWithCallbacks which takes an AudioFile_WriteProc (function pointer) as an argument. This function is then called by the AudioFile object when there is data that needs to be written to the stream. I just don't see why I also need to specify AudioFile_ProcProc or if there is any way around this. – dave96 Jun 16 '12 at 18:01

1 Answers1

1

Apple documentation is wrong here. Check header file AudioFile.h:

/*!
@typedef    AudioFile_SetSizeProc
@abstract   A callback for setting the size of the file data. used with AudioFileOpenWithCallbacks or AudioFileInitializeWithCallbacks.
@discussion a function that will be called when AudioFile needs to set the size of the file data. This size is for all of the 
            data in the file, not just the audio data. This will only be called if the file is written to.
@param      inClientData    A pointer to the client data as set in the inClientData parameter to AudioFileXXXWithCallbacks.
@result                     The callback should return the size of the data.
*/

typedef OSStatus (*AudioFile_SetSizeProc)(
                            void *      inClientData,
                            SInt64      inSize);
Wojciech
  • 330
  • 2
  • 13