mnearents
mnearents

Reputation: 676

Core Audio - Write data to beginning or middle of audio file (somewhere other than the end)

So, I have an audio recording iOS app I am working on. In my app I have the need to write audio at any point in the file (in the documents directory) the user chooses, which will overwrite whatever audio is there.

Example: I record 3 min of audio, scroll back to minute two, start recording again for 10 seconds. Now, 2:00 - 2:10 contains the new audio, and the old audio is gone (the audio file does not get longer in this example).

I am using EZAudio and I can record and pause as many times as I want and it will keep appending to the end. I was going to use ExtAudioFileSeek to seek backward in the file and record from there, but you can only use that when the file is open as read-only.

What I don't want: I don't want to record to a different file, and append the two files together using this method: https://stackoverflow.com/a/10562809/1391672 There is significant loading time associated with this. The iOS app Voice Memos appends files together instantaneously.

Can ExtAudioFileWriteAsync be used to append audio at the beginning? Or at a specified sample location? Is there another method I should look at?

Upvotes: 3

Views: 523

Answers (1)

dave234
dave234

Reputation: 4955

I think ExtAudioFileSeek is undefined when recording. I use the AudioFile API which ExtAudioFile is built upon. The only catch i that you have to do your own format conversions (I use an AudioConverterRef if necessary). But once you've got all of that squared away you can call AudioFileWritePackets which takes an inStartingPacket argument so you can write anywhere in the file. You can also wrap an AudioFileRef in an ExtAudioFileRef for playback while the file is still open for recording using ExtAudioFileWrapAudioFileID. Headers are in AudioFile.h and AudioConverter.h.

Upvotes: 1

Related Questions