使用扩展音频文件服务 (ExtAudioFileRead) 提取浮点数
我正在尝试编写一个程序来记录音频文件中样本的浮点值。我的步骤如下:
- 打开扩展音频文件
- 设置音频格式 (AudioStreamBasicDescription)
- 将音频格式应用于我的扩展音频文件
- 设置 AudioBufferList
- 使用 ExtAudioFileRead() 将扩展音频文件读取到 AudioBufferList 中
- 记录 AudioBufferList 的浮点值
我已将整个 90 行课程的要点如下: https://gist.github.com/792630
问题是,如果我将音频格式应用于扩展音频文件(步骤 3),我在尝试读取该文件时会遇到错误(步骤 5)。如果我注释掉第 5 步,文件读起来很好,但我不会强制执行读取格式,并且在记录时不会出现浮动。
任何建议将不胜感激。谢谢!
I'm trying to write a program to log the float values of samples in an audio file. My steps are as follows:
- Open an Extended Audio File
- Set up audio format (AudioStreamBasicDescription)
- Apply audio format to my Extended Audio File
- Set up an AudioBufferList
- Read Extended Audio File into AudioBufferList with ExtAudioFileRead()
- Log float values of AudioBufferList
I've put the entire 90 line class in this gist: https://gist.github.com/792630
The trouble is, if I apply an audio format to my Extended Audio File (Step 3), I get an error trying to read the file (Step 5). If I comment out step 5, the file reads fine but I will not have enforced my format for the read and I don't get floats when logging.
Any suggestions would be greatly appreciated. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我立即注意到的一件事是,您在堆栈上分配了一个 AudioBufferList,但将 mNumberBuffers 设置为 2。在堆栈上使用 ABL 很好,但如果您这样做,它们只能包含一个缓冲区。但由于您已将客户端格式设置为单声道,所以这不是您真正的问题。
真正的问题是您没有将 fileRef 的地址传递给 ExtAudioFileOpenURL - 您正在传递值 - 因此调用无法正确初始化变量。
调用应该如下所示:
我这样做了,编译了您的代码,一切正常。
One thing I noticed right away is that you are allocating an AudioBufferList on the stack but setting mNumberBuffers to 2. It's fine to use ABLs on the stack, but if you do that they can only ever contain one buffer. But since you've set the client format to mono that isn't your real problem.
The real problem is that you aren't passing the address of fileRef to ExtAudioFileOpenURL- you're passing the value- so there is no way that the call can initialize the variable properly.
The call should look like this:
I did that, compiled your code and everything worked fine.