Extract floats with Extended Audio File Services (ExtAudioFileRead)
I'm tryi开发者_如何学Pythonng 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!
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.
精彩评论