CocoaDev

Edit AllPages

Hello,

I’m trying to use Apple’s Audio Extraction API (http://developer.apple.com/quicktime/audioextraction.html) to write a method that will load a WAV file (or any media file, I suppose) and put the audio contents into a buffer of floats.

It’s very hacky and full of potential bugs (ie, I’ve hardcoded the size of the buffers, for a start!) but I’ll fix those later. For the time being I want to know why the actual call to MovieAudioExtractionFillBuffer is failing with code -2209 (badCallOrderErr), since everything right up to that call runs correctly (or so it appears to in the debugger).

Can anyone see what I’m doing wrong (other than the obvious hack type stuff)?

Any suggestions most appreciated!


I thought I’d follow up on my original post. I’ve updated the code below and this mostly works for pretty much any media file containing audio. It takes an NSString with a URL (such as @”file:///test.mov”), imports it and stores it as interleaves floats in a buffer called samples* (which you need to provide). sampleCount is a count of the number of samples, too.

Caveat: Bugs lie herein, code could be much more stable but seems to work. Non-stereo files seem to fail, perhaps I have something wrong in the way I set up the asbd. Any comments/advice warmly welcomed.

float* samples; UInt32 sampleCount;

// import from a URL, such as file:///test.mov

}