开发者

Extract floats with Extended Audio File Services (ExtAudioFileRead)

开发者 https://www.devze.com 2023-02-06 02:34 出处:网络
I\'m tryi开发者_如何学Pythonng to write a program to log the float values of samples in an audio file. My steps are as follows:

I'm tryi开发者_如何学Pythonng to write a program to log the float values of samples in an audio file. My steps are as follows:

  1. Open an Extended Audio File
  2. Set up audio format (AudioStreamBasicDescription)
  3. Apply audio format to my Extended Audio File
  4. Set up an AudioBufferList
  5. Read Extended Audio File into AudioBufferList with ExtAudioFileRead()
  6. 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!


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:

CheckResult(ExtAudioFileOpenURL(inputFileURL, &fileRef), "ExtAudioFileOpenURL failed");

I did that, compiled your code and everything worked fine.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号