我试图打开一个文件并使用ExtAudioFileWrite将数据追加到它。现在,创建/初始写入(创建时)/转换工作很好,但不幸的是,我似乎无法打开文件以供后来写入。只有一个函数似乎打开文件:ExAudioFileOpenURL
,但仅用于阅读。那么,如果我无法打开文件进行写入,我该如何在文件末尾编写代码?使用ExtAudioFileWrite在文件末尾写入
回答
我可能是错的,或不完全理解你的问题。但是,一旦使用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);
这将无法编译,我猜。但希望能帮助你明白这个想法。
是的,如果你保持文件打开,它会工作得很好。但是,如果关闭它然后再次打开它将从头开始写入。我通过直接使用AudioFile解决了问题,我不认为扩展版本具有此功能。 –
如果你读到一个缓冲区,就像在你的例子中,内存将在某个时候是一个问题(这是在我的情况) –
就像我说的,我可能不完全理解你需要什么。我很高兴你知道了。对不起,我不能有任何帮助。 – Dan1one
- 1. 在文件末尾写入
- 2. 通过opencsv在文件末尾写入
- 3. 在文件的末尾写入新行
- 4. 如何使用stream aws s3 php在文件末尾写入?
- 5. ExtAudioFileWrite只写入文件的第一位
- 6. 如何在文本的末尾写入新的数字文件
- 7. 我如何写文件在文件末尾的文件在c + +
- 8. 如何在文件末尾的特定地址写入
- 9. 如何防止在文件末尾写入“\ n”
- 10. 写入文件,但不只是在末尾
- 11. 如何停止在csv文件末尾写入空行 - pandas
- 12. ofstream不写入到C++现有文本文件的末尾
- 13. 使用VIM从文件末尾搜索
- 14. 写在xml的末尾
- 15. 如何在C#中的文本框的末尾写入文本?
- 16. 将字符串写入文件末尾(C++)
- 17. XmL文件,需要写入“通道”元素的末尾
- 18. “已解决”末尾带空格的写入文件
- 19. 如果两个东西不匹配,写入文件末尾
- 20. DeflaterOutputStream:写入超出流末尾
- 21. 使用ExtAudioFileWrite将Streamed mp3数据包的缓冲区写入wav文件ios
- 22. 在URL末尾添加文本输入
- 23. 在写入文本文件之前删除字符串末尾的空行?
- 24. 如何在每行末尾的文本文件中写入内容
- 25. 写入文件结尾
- 26. mmap超出文件末尾
- 27. 文件末尾要求
- 28. HTML文件末尾的CSS
- 29. 文档末尾的事件
- 30. 在末尾插入链表
你试过'AudioFileOpenURL'然后'ExtAudioFileWrapAudioFileID'吗? – sbooth