Mixing Audio Files
Asked Answered
G

2

4

I have few audio files:

  • f_1 - length 10 sec
  • f_2 - length 3 sec
  • f_3 - length 1 sec

What I need is to find a way to mix(merge) f2 and f3 at particular section in f_1 (i.e. position which is equal to 6 sec)

I was looking at Audio examples but they don't help me much so any ideas\references\ documentation that might help?

Many Thanks!

Gellman answered 3/2, 2010 at 11:11 Comment(9)
Are you looking for an Android-specific solution or do you just want to know in general how you combine (mix) sampled audio programatically ?Homozygous
I'm looking for Android specific solution. Well, I'm not expecting solution but rather something like reference to classes I should look on (if there are such). Thanks!Gellman
Are you looking to mixing the audio down to a file? Or are you tying to mix the audio over the audio channel?Rede
@Rede Yes, down to the file that can be processed later .Gellman
@Rede Although mixing over audio channels would be acceptable if I can somehow redirect output to the file.Gellman
Do you want f_2 and f_3 just inserted at given points in f_1, or do you want a true mix of f_1 and say f_2? For instance, do you want it to be a 50% mix of f_1 and f_2 in the period of 1 to 4 seconds in f_1?Anallese
What is the audio file format (WAV, MP3, ...)? Do all the 3 audio files have the same audio format (44.1 KHz/16 bit/stereo, 128 KBps MP3, ...)?Maverick
@Adal They all have same format (mp3).Gellman
Hi, i want two merge two mp3 audio files into one file.please help me if u know how to merge them. for example 1st is 1min and 2nd is 45 sec thwn the output should be in one min. thanks in advanceSupertax
R
6

Unfortunately, I don't think there's anything on the device to do file mixdowns. As I see it, you've got two options:

1) Send both files to a server and use ffmpeg or some other free tool to do the mixdowns.

2) If it's something that must stay local to the phone, you could load the audio using the Android SoundPool (http://developer.android.com/reference/android/media/SoundPool.html) and set them to play at the same time. You can find a good tutorial on the subject here: http://www.droidnova.com/creating-sound-effects-in-android-part-1,570.html

The sound pool requires you to manage multiple files rather than doing mixdowns and playback of a single file. It would be cool if the soundpool let you grap the output as a IOStream but, alas, the SDK doesn't seem to allow it. Further, it would be nice if the AudioRecorder allowed you to grab a stream from the music layer...but that doesn't look possible either. List of audio inputs: http://developer.android.com/reference/android/media/MediaRecorder.AudioSource.html

I know this isn't exactly what you're looking for, but hopefully you can get a workaround from some of the links.

Rede answered 12/2, 2010 at 18:16 Comment(1)
This is a terrible answer based in a fundamental misunderstanding of what mixing is. Mixing audio files merely requires that they both be converted to linear PCM, scaled appropriately, and the samples added. There's no need to export the data to an external server, an Android device is a fine computer in its own right.Lody
S
0

What about converting it to wave and doing a FFT, muxxing it at the desired range ["by hand"] and doing an iFFT and convert it back to mp3.

Note: This involves some math and you should know at least something about how Fourier Transformation works before actual coding.

Note: I don't know if there are "libs" that allow pleasent access to FFT, seeking and/or muxing.

Please correct me if I got a mindflaw, but I think this should work.

Severity answered 13/2, 2010 at 0:50 Comment(1)
Once you have wav (linear PCM) data, no FFT would be involved - mixing can be done quite readily in the time domain so no transformation to the frequency domain is needed.Lody

© 2022 - 2024 — McMap. All rights reserved.