Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I Access/extract raw(headless) audio data from a caf file on iPhone?

I am working on a project that requires me to send raw headerless ulaw or linear pcm data to a server.

I am using the AVAudioRecorder and I can save out audio files to the phone quite easily, but the problem is that it no matter what I try and do, they get wrapped in a caf file or stamped with some kind of header.

It's my understanding that a caf file is just a wrapper file for raw audio data and that this audio data can be in various formats including linear pcm and ulaw.

So my questions are, how can I generate a raw audio file without the caf wrapper to begin with (ie just the headerless raw audio stuffed into a file) or if I record a caf that contains the raw Ulaw or linear pcm audio data, how can I easily go in and extract just the raw audio data from the caf file and leave everything else behind.

like image 278
rhart Avatar asked Oct 20 '10 21:10

rhart


2 Answers

If you use the Audio Queue API for recording, instead of AVAudioRecorder, you will have access to raw PCM sample buffers, and can write those out to a flat file for later sending to your server.

like image 182
hotpaw2 Avatar answered Sep 17 '22 17:09

hotpaw2


If the audio data in the CAF is already in the format you need it in, I'd use the AudioFile API to grab the caf file's audio data and write them to a headerless/RAW file before uploading to my server.

If you need to convert the CAF's data, use the ExtAudioFile API instead. Either way, pretty straightforward.

http://developer.apple.com/library/ios/#documentation/MusicAudio/Reference/AudioFileConvertRef/Reference/reference.html

http://developer.apple.com/library/ios/#documentation/MusicAudio/Reference/ExtendedAudioFileServicesReference/Reference/reference.html

like image 28
Art Gillespie Avatar answered Sep 19 '22 17:09

Art Gillespie