Saving audio to file (ie wave/mp3/aiff)

Has anyone used ofSoundStream and recorded/saved to file the result? Any recommendations for saving audio to file on iOS?

This is the best description I’ve found.

http://stackoverflow.com/questions/1010-…-iorecorder

Yeah, I read that although I didn’t really understand it. Is it just recording whatever is outputting or do we need to feed something into it like the audiobuffer from ofSoundStream. I’ll try the code further down on the page which looks more complete and see if it works.

I’m actually using ofxPd and I’ve been able to record to file using the writefs~ object, however for some reason it only is saving 2-3 seconds of audio.

So just curious what the options are and if anyone has implemented this in OF. We might not need a native obj-c method which would be beneficial for other projects that aren’t for OF.

Unfortunately, the link above doesn’t work since AVAudioRecorder only does mic input.

I’m still looking for a method to save the audio buffer to file. I’m looking at audio queues in the iOS sdk, but there should be non-iOS methods for rendering audio - I’m just not familiar enough with audio in c++/iOS. possibly an openAL method would be possible too.

Any thoughts for saving internal audio (audio output)?

Hey

I am just wondering if you solved this as I am looking to record, save and playback sound on iOS.

Thanks
Chris

interested too here :slight_smile:

I never did solve this because I ended up using ofxPD addon and using PD’s [writesf~] to write to file. If you’re already using ofxPD, then it makes sense to use this, but if you’re not it’d be more of a hack. I do have code however to compress the wav file to m4a/m4r afterwards using obj-c, but I never went back to see how to do the recording natively. I’d still love to know myself.

Some posts that may help narrow it down:

Nice to read that, Seth.
I guess ofxPD write the file into data/

How can we provide an easy way to users to grab that file for further listening purpose …?
Did you find a nice way ?

Well, for ofxPD and [writesf~] you have to send it the path to save to. So you send it the documents (ofxiPhoneGetDocumentsDirectory()) with the filename you want. So since you’re the one setting the path and filename, you know where it is.

BTW, looks like the forum deleted one of my posts with some possible helpful links. I’ll try to recover those links in a minute.

This may help for doing native recording.

http://developer.apple.com/library/ios/#samplecode/SpeakHere/Listings/Classes-AQRecorder-mm.html#//apple-ref/doc/uid/DTS40007802-Classes-AQRecorder-mm-DontLinkElementID-14

There were another couple links, but i’ll have to try to find them later (having a hard time right now).

But can you write everywhere?
afaik, apps are confined in sandbox place no?

If I can write everywhere, the thing would be to write into … the mp3 place and, as you wrote, to manipulate format/encoding a bit to make them available easily .hm…

No, you can’t write anywhere. You can write only to your own sandbox. The ofxiPhoneGetDocumentsDirectory is the path to the documents directory. You can either write to the documents directory (recommended) or the library. The library is not accessible to users through iTunes, but the Documents directory is (if you turn on Filesharing in your plist). So, it’s recommended to write to the documents directory.

Documents place seems to be the way to go
Many thanks Seth.
I’ll take a look at this

for reference:

http://developer.apple.com/library/ios/#releasenotes/General/WhatsNewIniPhoneOS/Articles/iPhoneOS3-2.html#//apple-ref/doc/uid/TP40009337-SW11

testing that on tomorrow =)

I got this working using mareks wav file writer: https://github.com/mazbox/ofxmarek/blob/master/mareklib/audio/WavFile.h

iirc, i save to the wave file in realtime, and then close it up when it is done writing. I seem to recall that I could get a few minutes of audio out of it.

nearly all the stuff here is done using that method: http://soundcloud.com/jonbro/sets/fun-a-day-2012/

Nice jonbro! I’ll have to give that a try too. Looks like it’s a good cross-platform solution.

any final solution to make the record available from an external computer ?
I cannot understand if I have to compress it or if I can use pure PCM stuff.

@jonbro thanks for posting Mareks class, looks good.

You doing this in iOS? What location does it save the WAV to on the device? Does it keep the file there when you restart the phone or only temporary in memory?

Cheers