views:

222

answers:

5

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.

A: 

I found this. Haven't tried it as it does not provide all the functionality I'm seeking, but at least it's something.

http://www.codeproject.com/KB/audio-video/CWave.aspx

quano
A: 

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

Piotr Czapla
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.
quano
+2  A: 

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.

Fred
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.
quano
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.
Fred
+2  A: 

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?

slf
A: 

Check out this answer to one of my questions. Maybe it will help.

Malki