I'm using sox 14.2.0 on Centos 6.0.

I have two mono wav files, left.wav and right.wav. I need to combine them into one stereo.ogg file, with left.wav pan 80% to the left, and right.wav pan 80% to the right.

I was unable to come up with the sox options needed for this. How do I do this?

This is going to be executed repeatably for many files, so I'd prefer an efficient solution. From what I understand there should be a way to do it in one pass (one invocation of sox).


haimgs command is not completely right. Classically you pan by reducing the volume of only one channel. That means: if you want your signal to be 80% left, the left channel keeps the original volume while the right channel only gets 20% of the original volume. At least that's what sox's panning code did (and what Alan Blumlein seems to have propesed when inventing stereo).

Also his command can be shortened using the remix-option.

Therefore the corrected and shortened command is:

sox left.wav right.wav stereo.ogg remix 1,2v0.2 1v0.2,2

edit in answer to haimgs comment:

sox will warn you if clipping occours. But yes, it is possible. With the remix-option every channels volume is scaled with the factor 1/n, where n is the number of input channels. But thats only used if NO VULME OPTION is specified for the output channel (so your 100% + 20% is correct).

sox also has an option to scale any channel without explicit volume information, just add an "-a" after "remix" (like "remix -a 1,2v0.2 1v0.2,2") and the volumes will be like 50% +20% = 70%. It's pretty confusing and by now I'm not shure whether you also have to scale the panned channels volume by 1/n, which would result in "remix -a 1,2v0.1 1v0.1,2", or 50% + 10% = 60%. I will have to further investigate in this direction. Meanwhile you could read the remix-section in the man page of sox (also available at the sox homepage).

edit after further reflecting:

After thinking about it I am pretty shure that you have to scale the panned volumes by 1/n, too.

About the clipping issue: By dividing ALL the volumes by the number of channels, this problem can not occur. But that does not preserve the original power of the signal, because the power of a signal is logarithmic, not linear. The more channels you mix, the more silent the signal should become. That's why sox also got options for that, where the volumes get scaled by 1/sqrt(n). To use this, just take a "p" instead of a "v" at the remix-part and adjust the values accordingly, and also add a "-p"-option after the remix-statement. You can see the difference of scaling by 1/n and by 1/sqrt(n) here.

The following is how I think to compute the correct power values : for each channel you have to solve 20*log_10(factor). A factor of 2 will result in ~6(dB), a factor of 0.5 will result in ~-6(dB). That's exactly what the sox manual says, so I guess this is right.

So, finally the command in you case should be:

sox left.wav right.wav stereo.ogg remix -p -a 1,2p-6 1p-6,2

I don't have sox on this machine, so I can't test this command for correct syntax, so please tell me if there is a problem. I will test all this theory as soon as I get the chance to, because I will face a simmilar issue, but I will have to mix many more channels than just 2, and that is why I came up with that signal power stuff.

  • Wouldn't that introduce clipping? E.g. 100% L + 20% R = 120% volume, If both channels go to the max? – haimg Nov 30 '11 at 15:25
  • You don't add the volumes of the channel, otherwise you'd have 240% at max volume, and that's just weird. – Rob Nov 30 '11 at 15:57
  • @Rob: You may have forgotten that by your definition we also had "200%" volume in the beginning. – causa prima Nov 30 '11 at 16:18
  • Think of it this way, haimg. You've got a max of 100% audio on each channel. So, when you remix the left.wav and right.wav into stereo.ogg, what you're doing is making a NEW left.wav and right.wav, each with the other one in them VERY QUIETLY. It's still 100% for each channel, it's just the channel happens to have some of the other channel hard coded in. It's not like you'll lower the volume of the left channel and completely remove that audio from the right channel. – Rob Nov 30 '11 at 16:26
  • "If both channels go to the max", like haimg said, he would be right. Think of it that way, rob. When combining the two channels you add the sample values. Let's asume we have 8 bit audio, then the maximum sample value would be 256 (in the unsigned case). If you add ANYTHING (like 51, the 20% of 256) to this sample value of 256 it will get bigger than the maximum sample value possible and clipping will occur, so it does not matter whether the other signal is very quietly or not - it WILL clip. – causa prima Dec 1 '11 at 8:21

Here's how it is done:

sox left.wav right.wav --channels 2 --combine merge stereo.ogg mixer 0.8,0.2,0.2,0.8


Somehow all the above generated errors for me. This is what worked for me (SOX on Ubuntu 14.04):

sox -M -c 1 lef.wav -c 1 right.wav output.mp3 

Use sox with the pan option to pan one file to the hard right and the other to the hard left (1 and -1 respectively). Then use soxmix to mix the two together.

  • sox 14.2 does not include soxmix, pan option is deprecated, and I was hoping to do it in one pass. – haimg Oct 20 '11 at 15:01
  • sox has a mixer option: mixer [ −l|−r|−f|−b|−1|−2|−3|−4|n{,n} ] ( see: sox.sourceforge.net/sox.html#SYNOPSIS ). Hard to tell from the doc, but it looks like you specify -m to mix the two files, which happens before the effects chain (where mixer happens) – horatio Oct 20 '11 at 15:25

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.