2

I need to mix audio files of different types into a single output file through code in my iPad app. For example, I need to merge a .m4a file with .mp3 or .wav or any other format file. The resulting output file should be of .m4a type.

I have compiled FFMPEG for iOS with the link: http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/2009-October/076618.html

Now, I am not able to understand in which direction to proceed?

iPhoneDev
  • 1,547
  • 2
  • 13
  • 36
  • Can you define what you mean by mixing? in FFMPEG you could combine to mono tracks into one stereo track. But i don't think ffmpeg will let you 'mix' in the conventional sense, it's designed for conversion. – Twelve47 Apr 19 '11 at 10:09
  • 1
    By mixing I mean that: Suppose I am having a file with drum beats and another with guitar sound.When mixed the output file should play both the music simultaneously like a complete instrumental. – iPhoneDev Apr 19 '11 at 10:18
  • I don't think ffmpeg will let you do that. – Twelve47 Apr 19 '11 at 10:32
  • 2
    Is there any other way to do this. Also , I have to add reverb effect to a .m4a file. Is there any such library or api by which I can achieve both? – iPhoneDev Apr 19 '11 at 10:35
  • @iPhoneDev :Can you please share how you have achieved with sound mixing of diferent format file? I have the same query.I have tried mixing of two .caf files, it is working. But when I am trying to mixing different format, it is not working. It would be great, if you can give some guidenece on this. – spaleja Mar 09 '12 at 12:21

1 Answers1

0

This is more of a suggestion than an answer. I don't have any experience with obj-c, though I have worked with audio formats in other languages. Unless you find some library that does this specific task, you may need to decode the files and convert their data to some common numerical representation.

The sample data of a .wav file is stored as signed integers between the range of -32768 to 32767, while mp3 sample data is stored as floating points between the range of -1 to +1. Either representation could be converted to the other through some simple calculation.

mp3ToWavSample = mp3Sample * 32767

Once the data is converted "merging" becomes very easy. You can simply add the sample values together.

mergedSample = convertedSample1 + convertedSample2

You would need to apply this to every sample in the mp3. Depending on the size of your files, this could be a significant processing task.

As for adding reverb to your track, I'd suggest that you ask for help on that in a another question.

JeremyFromEarth
  • 14,344
  • 4
  • 33
  • 47