tassock
tassock

Reputation: 1653

Extract floats with Extended Audio File Services (ExtAudioFileRead)

I'm trying 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!

Upvotes: 3

Views: 2268

Answers (1)

sbooth
sbooth

Reputation: 16976

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.

Upvotes: 3

Related Questions