Mixing sound files on an iPhone
Asked Answered
L

3

6

I've got a couple of wav files and possibly a mp3 that I'd like to mix down to a single wav or mp3-file. I'm using C/C++/Obj-C (iPhone). I have really no experience with this sort of thing. If anyone could give me some pointers, I would be very grateful.

Basically what I want to do is similar things like for example Audacity can do, but programmatically. Isn't there a sound library where you can easily open audio files and "paste" them into a new one at defined positions? Where mixing is something you don't have to worry about?

Thanks.

Legend answered 16/4, 2010 at 14:7 Comment(4)
Can you clarify whether you want to play your files simultaneously or mix them and then write the result out to a file? If the latter, is there a reason you can't preprocess them to create a single file in advance? If the former, you're probably going to want to read up on Audio Queue Services or OpenAL, both of which are pretty deep subjects.Flossi
Edited question to be more clear. Yes, sounds could be simultaneous.Legend
@Legend hv u find solution for that???Admit
@Admit I haven't implemented anything concerning this, and haven't looked into it since I asked. Things might've changed now and there might be easy-to-use libraries. I suggest you look into it and come back if you find anything. :)Legend
T
3

Mixing two sound buffers of linear PCM is only a matter of adding each sample value in them together, and of course make sure you don't overflow. Normally you would use floating point values in the buffers though, so the issue is when you go back to the file. You should also have CoreAudio available on the iPhone, it has all the means to open/read/write sound files in different formats. I think there is also a more high level api available to the iPhone that isn't on the mac, look up the apple docs.

Teresa answered 18/4, 2010 at 17:14 Comment(2)
Yeah, I've understood this as well. It isn't hard to do, but requires some work. I figured someone must have done this before, maybe even made a simple lib for it. That would save me some time. Reading files, adding values and writing out isn't the most exciting of things I can think of. :) It just seems like such a trivial feature. I was really surprised by how hard it seems to be to find an already existing lib that does this. So far I have not found anything in the docs that explains how you open several files, place them at specific positions in time and mix them down to a single file.Legend
Ok, but there are support for this in the API, you need to fill up a struct with some properties of your file format if I remember correctly, then send it to some of the library function. It was a while ago since I've done this, but I'd say that format conversion of a multitude of audio formats is non trivial, it's all supported and done for you by the API. A thing like a time line I think you have to invent yourself unless it's realtime playback your after, it's also supported by the API. But it shouldn't be too hard to do since you can get it by (time * sample requency) to get a bufferindex.Teresa
F
2

If you are specifically looking for the features of Audacity, it uses PortAudio under the hood (looks like an MIT license). Perhaps you can just try to use that?

Fluid answered 23/4, 2010 at 13:32 Comment(0)
F
0

Read Multimedia support as a starting point it contains alot info. Here is an extract:

There are 3 ways to mix the audio on iphone:

  • Audio Unit framework
    • Multichannel Mixer - "lets you mix multiple audio streams to a single stream"
    • 3D Mixer unit - "lets you mix multiple audio streams, specify stereo output panning, manipulate sample rate"
  • OpenAl used in games development

Also check the following sample out: iPhoneMultichannelMixerTest:

Two input busses are created each with input volume controls. An overall mixer output volume control is also provided and each bus may be enabled or disabled

Flesh answered 18/4, 2010 at 16:41 Comment(1)
Note that I don't want to play the files (on the iPhone), just do stuff with them and save to a new file. :) I will check the links.Legend

© 2022 - 2024 — McMap. All rights reserved.