13

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).

haimg
  • 23,153
  • 17
  • 83
  • 117

4 Answers4

9

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 
bwDraco
  • 46,683
Roger
  • 91
7

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

haimg
  • 23,153
  • 17
  • 83
  • 117
5

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.

0

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.

albal
  • 1,251
  • 1
  • 11
  • 23