1

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?

4

1 回答 1

0

我可能错了,或者没有完全理解你的问题。但是,一旦您开始使用 ExtAudioFileWrite 写入文件,您可以通过再次调用 ExtAudioFileWrite 继续写入文件。我即将冒险在没有编译器的情况下进行编码,希望你能明白

例子:

....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);

我猜这不会编译。但希望能帮助您了解这个想法。

于 2012-10-22T10:31:58.927 回答