iphoneobjective-cioscocoa-touchcaf

How to merge two audio files using iPhone SDK?


I would like to merge two .caf audio files in my iPhone App?

Can you please let me know how?

Thanks!


Solution

  • OPTION-1:

    Refer to this link:

    Join multiple audio files into one

    Answer of invalidname in that post says:

    MP3 is a stream format, meaning it doesn't have a bunch of metadata at the front or end of the file. While this has a lot of downsides, one of the upsides is that you can concatenate MP3 files together into a single file and it'll play.

    This is pretty much what you're doing by concatenating into an NSMutableData, the downside of which is that you might run out of memory. Another option would be to build up the file on disk with NSFileHandle.

    This doesn't work for most file formats (aac/m4a, aif, caf, etc.). MP3 is literally just a stream dumped to disk, with metadata in frame headers (or, in ID3, tucked between frames), so that's why it works.

    OPTION-2:

    combine two .caf audio files into a single audio file in iphone

    Answer by Midhere in this post:

    You can do it using ExtAudioFileService. In ios developer library they had provided two examples to convert one audio file to another format. In these they are opening one audio file for reading and another file for writing (converted audio). You can change or updated code to read from two files and write them to one out put file in same format(caf) or compressed format. First you have open first audio file and read every packets from it and write it to a new audio file. After finishing first audio file, close the file and open second audio file for reading. Now read every packets from second audio file and write to newly created audio file and close second audio file and new audio file.

    Please find the links(1,2) for these sample codes .... Hope this helps you...and good luck. :)

    So try and convert it to another format and then try combining it.

    OPTION-3:

    Refer to:

    Joining two CAF files together

    Answer by dineth in this post:

    If anyone is keen to know the answer, there is a way to do it. You have to use the AudioFiles API calls. Basically, you'd:

    create a new audio file using AudioFileCreate with the correct parameters (bitrate etc). open your first file, read the packets and write them to the newly created file. open your second file and do the same. make sure your counters are not zero-ed out after writing the first file. AudioFileClose -- and you're done! Things to note: for local files, you have to run a method to escape spaces

    That's about it!

    OPTION-4:

    Slightly in a different note.

    I think you are recording files in CAF and trying to combine them.So in that case you can finally try recording your files in some other format than caf.

    Try out this link for that:

    iOS: Record audio in other format than caf

    Hope this helps.