Using ExtAudioFileWrite to write at the end of a file
-
06-07-2021 - |
Question
I'm trying to open a file and append data to it using ExtAudioFileWrite. Now, creating/initial writing(on creation)/converting works just fine, but unfortunately I can't seem to be able to open the file for writing afterwards. There is only one function that seems to open the file: ExAudioFileOpenURL
but only for reading. So, how can I write at the end of a file if I'm not able to open the file for writing?
No correct solution
OTHER TIPS
I might be wrong, or not fully understanding your question. But, once you start writing to the file using ExtAudioFileWrite you can keep writing to it by calling the ExtAudioFileWrite again. I am about to venture into coding with no compiler, hopefully you will get the idea
Example:
....variables declaration and your logic.....
//1.Create File to write output
ExtAudioFileRef outputFile;
//+++++++ LOOP to append as many files as you want +++++++//
//2.Create file reference to files you want to merge
ExtAudioFileRef audioFileObject = 0;
//3.open the first file
ExtAudioFileOpenURL (firstFileURL, &audioFileObject);
//4.get file properties
AudioStreamBasicDescription AudioFileFormat = 0;
UInt64 numberOfPacketsToReadInCurrentFile = 0;
ExtAudioFileGetProperty(audioFileObject,
kExtAudioFileProperty_FileLengthFrames,
sizeof(numberOfPacketsToReadInCurrentFile),
&numberOfPacketsToReadInCurrentFile
);
ExtAudioFileGetProperty(audioFileObject,
kExtAudioFileProperty_FileDataFormat,
sizeof(AudioFileFormat),
&AudioFileFormat
);
//5.Set destination ASBD
ExtAudioFileSetProperty(audioFileObject,
kExtAudioFileProperty_ClientDataFormat,
sizeof (importFormat),
&importFormat
);
//6.Set/Create/Allocate Some Buffers
//use AudioFileFormat to setup your buffers accordingly
AudioBufferList theBufferList = 0 // bufferList setup (I dont remember that)
//7.Read the file into the buffer
ExtAudioFileRead(audioFileObject,&numberOfPacketsToReadInCurrentFile,theBufferList);
//8.Write the buffer to a File
ExtAudioFileWrite(outputFile, numberOfPacketsToReadInCurrentFile, theBufferList);
free(theBufferList);
//if you want to append more files go to point 2 with the next file URL
//+++++++CLOSE LOOP+++++++++//
//once you are done.. just dispose the file and clean up everything left
ExtAudioFileDispose(outputFile);
This will not compile, I guess. But hopefully will help you get the idea.