PDA

View Full Version : Audio up/downmix with SoX


Selur
11th January 2010, 21:53
Background: I wanted to add the possibility to up-/downmix the audio to sx264/Hybrid decoding with ffmpeg, piping the output to sox and then pipe it to ffmpeg or neroaacenc for encoding, problem is I found no documentation how to:
a. do a up/downmix with sox
b. do it in general, like what channels need to be mixed how

Anyone got infos on how to use SoX to do up- and downmixes and how up-/downmixes are done?

Cu Selur

tebasuna51
12th January 2010, 01:09
This Dolby ProLogic II downmix:
fl' = 0.3254xFL + 0.2301xC + 0.2818xSL + 0.1627xSR
fr' = 0.3254xFR + 0.2301xC - 0.1627xSL - 0.2818xSR

Can be implemented with SoX (and normalized) like:
sox 6w321.wav 2dpl.wav remix -m 1v0.3254,3v0.2301,5v0.2818,6v0.1627 2v0.3254,3v0.2301,5v-0.1627,6v-0.2818 norm

Of course you can use other coeficients for dpl I or simple stereo or add LFE to mix.

A correct upmix is more difficult to implement, in BeHappy there are some upmix functions using sox filter (thanks to NorthPole):
http://forum.doom9.org/showthread.php?p=787216#post787216

Selur
12th January 2010, 05:30
Cool thanks !

Cu Selur

Selur
12th January 2010, 12:26
Just tried to convert a 5.1 ac3 audio file (http://stashbox.org/765881/AC3-5.1.ac3) to mp3 using:ffmpeg -v 0 -threads 4 -i "AC3-5.1.ac3" -ac 6 -ar 48000 -acodec pcm_s16le -f wav - |
sox -t -s -b 16 -c 6 -r 48000 - -t wav - remix -m 1v0.3254,3v0.2301,5v0.2818,6v0.1627 2v0.3254,3v0.2301,5v-0.1627,6v-0.2818 norm |
ffmpeg -threads 4 -i - -ac 2 -y -ab 128000 -ac 2 -ar 48000 "test.mp3" and it seems like it's working, only problem is: 'rear right'-channel is missing. :)

tebasuna51
12th January 2010, 14:37
What ffmpeg version are you using?
(I can't pipe to sox with my version)

Warning (maybe a typo):
... sox -t -s -b 16 -c 6 -r 48000 - ... must be
... sox -t wav -s -b 16 -c 6 -r 48000 -

Selur
12th January 2010, 14:45
using here: SVN-r20817
used '-t wav' it just got lost on the way to the post ;)

Selur
12th January 2010, 15:01
Is there's some explanation somewhere how to get from http://en.wikipedia.org/wiki/Dolby_Pro_Logic#Dolby_encoding_matrices to:
Dolby ProLogic II downmix:
fl' = 0.3254xFL + 0.2301xC + 0.2818xSL + 0.1627xSR
fr' = 0.3254xFR + 0.2301xC - 0.1627xSL - 0.2818xSR
?

Cu Selur

Ps.: damn, must have changed something with the calls, since I can't get the pipe working anymore :(
got it, the '-y' is needed ;)
ffmpeg -y -i "AC3-5.1.ac3" -ac 6 -ar 48000 -acodec pcm_s16le -f wav - | sox -s -b 16 -c 6 -r 48000 -t raw - -t wav - remix -m 1v0.3254,3v0.2301,5v0.2818,6v0.1627 2v0.3254,3v0.2301,5v-0.1627,6v-0.2818 norm | ffmpeg -v -1 -threads 4 -y -i - -ab 128000 -ac 2 -ar 48000 "test.mp3"

Selur
12th January 2010, 19:31
Based on http://forum.doom9.org/showthread.php?p=1134992#post1134992 and the infos posted in this thread I tried to convert the infos from the other post:

function Dmix5Dpl2(clip a) # 5 Channels FL,LR,C,SL,SR
{
flr = GetChannel(a, 1, 2)
fcc = GetChannel(a, 3, 3)
lrc = MixAudio(flr, fcc, 0.3254, 0.2301)
// 0.3254*FL+0.2301*C 0.3254*FR+0.2301*C
bl = GetChannel(a, 4)
br = GetChannel(a, 5)
sl = MixAudio(bl, br, 0.2818, 0.1627)
// 0.2818*SL 0.1627*SR
sr = MixAudio(bl, br, -0.1627, -0.2818)
// -0.1627*SL -0.2818*SR
blr = MergeChannels(sl, sr)
//0.2818*SL+0.1627*SR -0.1627*SL-0.2818*SR
return MixAudio(lrc, blr, 1.0, 1.0)
//fl' = 0.3254*FL+0.2301*C+0.2818*SL+0.1627*SR
//fr' = 0.3254*FR+0.2301*C-0.1627*SL-0.2818*SR
}=> SoX remix part: 1v0.3254,3v0.2301,4v0.2818,5v0.1627 2v0.3254,3v0.2301,4v-0.1627,5v-0.2818

function Dmix6Dpl2Lfe(clip a) # 6 Channels FL,LR,C,SL,SR,SUB
{
flr = GetChannel(a, 1, 2)
fcc = GetChannel(a, 3, 3)
lrc = MixAudio(flr, fcc, 0.2646, 0.1870)
// 0.2646*FL+0.1870*C 0.2646FR+0.1870*C
lfe = GetChannel(a, 4, 4)
lrc = MixAudio(lrc, lfe, 1.0, 0.1870)
// 0.2646*FL+0.1870*C+SL 0.2646*FR+0.1870*C+SL
bl = GetChannel(a, 5)
br = GetChannel(a, 6)
sl = MixAudio(bl, br, 0.2291, 0.1323)
// 0.2291*SR 0.1323*SUB
sr = MixAudio(bl, br, -0.1323, -0.2291)
// -0.1323*SR -0.2291*SUB
blr = MergeChannels(sl, sr)
// 0.2291*SR+0.1323*SUB -0.1323*SR-0.2291*SUB

return MixAudio(lrc, blr, 1.0, 1.0)
//fl' = 0.2646*FL+0.1870*C+SL+0.2291*SR+0.1323*SUB
//fr' = 0.2646*FR+0.1870*C+SL-0.1323*SR-0.2291*SUB
}=> SoX remix part: 1v0.2646,3v0.1870,4,5v0.2291,6v0.1323 1v0.2646,3v0.1870,4,5v-0.1323,6v-0.2291

Since I'm not sure if I got it right what the GetChannel/MixAudio/MergeChannel do it would be cool if someone could recheck this. :)
(Especially the part that Dmix6Dpl2Lfe->SoX contains in both channel more Infos from SL than from SR let's me suspect that I got something wrong.)

Cu Selur

tebasuna51
13th January 2010, 02:11
Is there's some explanation somewhere how to get from http://en.wikipedia.org/wiki/Dolby_Pro_Logic#Dolby_encoding_matrices to:

Is a very old story, the coeficients I put was assumed in BeSweet-Azid dpl II downmix after a study, in this forum, to obtain the best channel separation. I can confirm the results.
...
[code]function Dmix6Dpl2Lfe(clip a) # 6 Channels FL,LR,C,SL,SR,SUB
...
lrc = MixAudio(lrc, lfe, 1.0, 0.1870)
// 0.2646*FL+0.1870*C+SL 0.2646*FR+0.1870*C+SL
...

Problems:
1) The correct channel order is FL,LR,C,SUB,SL,SR
2) You forget the 0.1870 when mix the SL (SUB)

Then must be:
fl' = 0.2646*FL +0.1870*C +0.1870*SUB +0.2291*SL +0.1323*SR
fr' = 0.2646*FR +0.1870*C +0.1870*SUB -0.1323*SL -0.2291*SR

And
1v0.2646,3v0.1870,4v0.1870,5v0.2291,6v0.1323 2v0.2646,3v0.1870,4v0.1870,5v-0.1323,6v-0.2291

Edit: Problems when use LFE (SUB) in the mix:
- Not recommended by Dolby because the mix can produce artifacts.
- The dpl decoder send the LFE content to Center channel (common part in FL-FR). The receiver must filter the low frequencies to subwoofer (the Center speaker can't be defined as "large")

Selur
13th January 2010, 09:05
Thanks for the help! :)

function Dmix6Dpl2Lfe(clip a) # 6 Channels FL, FR, C, LFE, SL, SR
{
flr = GetChannel(a, 1, 2)
fcc = GetChannel(a, 3, 3)
lrc = MixAudio(flr, fcc, 0.2646, 0.1870)
// 0.2646*FL+0.1870*C 0.2646FR+0.1870*C
lfe = GetChannel(a, 4, 4)
lrc = MixAudio(lrc, lfe, 1.0, 0.1870)
// 0.2646*FL+0.1870*C+SUB*0.1870 0.2646*FR+0.1870*C+SUB*0.1870
bl = GetChannel(a, 5)
br = GetChannel(a, 6)
sl = MixAudio(bl, br, 0.2291, 0.1323)
// 0.2291*SL 0.1323*SR
sr = MixAudio(bl, br, -0.1323, -0.2291)
// -0.1323*SL -0.2291*SR
blr = MergeChannels(sl, sr)
// 0.2291*SL+0.1323*SR -0.1323*SL-0.2291*SR

return MixAudio(lrc, blr, 1.0, 1.0)
//fl' = 0.2646*FL+0.1870*C+SUB*0.1870+0.2291*SL+0.1323*SR
//fr' = 0.2646*FR+0.1870*C+SUB*0.1870-0.1323*SL-0.2291*SR
}SoX: 1v0.2646,3v0.1870,4v0.1870,5v0.2991,6v0.1323 2v0.2646,3v0.1870,4v0.1870,5v-0.1323,6v-0.2291

Problems when use LFE (SUB) in the mix
will add a ToolTip regarding this once I integrate the whole thing into sx264/Hybrid, thanks for the info. :)

Cu Selur

Selur
13th January 2010, 10:54
For those interested, here's the full list with SoX remix calls: function Dmix3Stereo(clip a) # 3 Channels L,R,C or L,R,S
{
flr = GetChannel(a, 1, 2)
fcc = GetChannel(a, 3, 3)
return MixAudio(flr, fcc, 0.5858, 0.4142)
//0.5858*FL+0.4142*C 0.5858*FR+0.4142*C
}
SoX: 1v0.5858,3v0.4142 2v0.5858,3v0.4142

function Dmix3Dpl(clip a) # 3 Channels only L,R,S
{
flr = GetChannel(a, 1, 2)
sl = GetChannel(a, 3)
sr = Amplify(sl, -1.0)
blr = MergeChannels(sl, sr)
//S S*-1.0
return MixAudio(flr, blr, 0.5858, 0.4142)
//FL*0.5858+S FR*0.4142+S*-1.0
}
SoX: 1v0.5858,3 2v0.4142,3v-1.0

function Dmix4qStereo(clip a) # 4 Channels Quadro L,R,SL,SR
{
flr = GetChannel(a, 1, 2)
blr = GetChannel(a, 3, 4)
return MixAudio(flr, blr, 0.5, 0.5)
//FL*0.5+SL*0.5 FR*0.5+SR*0.5
}
SoX: 1v0.5,3v0.5 2v0.5,3v0.5

function Dmix4qDpl(clip a) # 4 Channels Quadro L,R,SL,SR
{
flr = GetChannel(a, 1, 2)
bl = GetChannel(a, 3)
br = GetChannel(a, 4)
sl = MixAudio(bl, br, 0.2929, 0.2929)
//0.2929*SR 0.2929*SL
sr = MixAudio(bl, br, -0.2929, -0.2929)
//-0.2929*SR -0.2929*SL
blr = MergeChannels(sl, sr)
//0.2929*SR-0.2929*SR 0.2929*SL-0.2929*SL <- Kann das Sinn machen?
return MixAudio(flr, blr, 0.4142, 1.0)
//0.4142*FL+0.2929*SR-0.2929*SR 0.4142*FR+0.2929*SL-0.2929*SL
}
SoX: 1v0.4142,4v0.2929,4v-0.292 2v0.4142,3v0.2929,3v-0.292

function Dmix4qDpl2(clip a) # 4 Channels Quadro L,R,SL,SR
{
flr = GetChannel(a, 1, 2)
bl = GetChannel(a, 3)
br = GetChannel(a, 4)
sl = MixAudio(bl, br, 0.3714, 0.2144)
//0.3714*SL 0.2144*SR
sr = MixAudio(bl, br, -0.2144, -0.3714)
//-0.2144*SL -0.3714*SR
blr = MergeChannels(sl, sr)
//0.3714*SL-0.2144*SL 0.2144*SR-0.3714*SR
return MixAudio(flr, blr, 0.4142, 1.0)
//0.3712*FL+0.3714*SL-0.2144*SL FR+0.2144*SR-0.3714*SR
}
SoX: 1v0.4142,3v03714,3v-0.2144 2,3v0.2144,3v-0.3714

function Dmix4sStereo(clip a) # 4 Channels L,R,C,S
{
flr = GetChannel(a, 1, 2)
fcc = GetChannel(a, 3, 3)
lrc = MixAudio(flr, fcc, 0.4142, 0.2929)
//0.4142*FL+0.2929*C 0.4142*FR+0.2929*C
blr = GetChannel(a, 4, 4)
return MixAudio(lrc, blr, 1.0, 0.2929) //<- instead of MixAudio(flr, blr, 1.0, 0.2929)
//0.4142*FL+0.2929*C+0.2929*SUB 0.4142*FR+0.2929*C+0.2929*SUB
}
SoX: 1v0.4142,3v0.2929,4v02929 2v0.4142,3v0.2929,4v02929

function Dmix4sDpl(clip a) # 4 Channels L,R,C,S
{
flr = GetChannel(a, 1, 2)
fcc = GetChannel(a, 3, 3)
lrc = MixAudio(flr, fcc, 0.4142, 0.2929)
//0.4142*FL+0.2929*C 0.4142*FR+0.2929*C
sl = GetChannel(a, 4)
sr = Amplify(sl, -1.0)
blr = MergeChannels(sl, sr)
//SUB -1,0*SUB
return MixAudio(flr, blr, 1.0, 0.2929)
//0.4142*FL+0.2929*C+SUB 0.4142*FR+0.2929*C-1.0*SUB
}
SoX: 1v0.4142,3v0.2929,4 2v0.4142,3v0.2929,4v-1.0

function Dmix5Stereo(clip a) # 5 Channels L,R,C,SL,SR
{
flr = GetChannel(a, 1, 2)
fcc = GetChannel(a, 3, 3)
lrc = MixAudio(flr, fcc, 0.3694, 0.2612)
//0.3694*FL+0.2612*C 0.3694*FR+0.2612*C
blr = GetChannel(a, 4, 5)
return MixAudio(lrc, blr, 1.0, 0.3694)
//0.3694*FL+0.2612*C+0.3694*SL 0.3694*FR+0.2612*C+0.3694*SR
}
SoX: 1v0.3694,3v0.2612,4v0.3694 2v0.3694,3v0.2612,5v0.3694

function Dmix5Dpl(clip a) # 5 Channels L,R,C,SL,SR
{
flr = GetChannel(a, 1, 2)
fcc = GetChannel(a, 3, 3)
lrc = MixAudio(flr, fcc, 0.3205, 0.2265)
//0.3205*FL+0.2265*C 0.3205*FR+0.2265*C
bl = GetChannel(a, 4)
br = GetChannel(a, 5)
sl = MixAudio(bl, br, 0.2265, 0.2265)
//0.2265*SL 0.2265*SR
sr = MixAudio(bl, br, -0.2265, -0.2265)
//-0.2265*SL -0.2265*SR
blr = MergeChannels(sl, sr)
//0.2265*SL-0.2265*SL 0.2265*SR-0.2265*SR
return MixAudio(lrc, blr, 1.0, 1.0)
//0.3205*FL+0.2265*C+0.2265*SL-0.2265*SL 0.3205*FR+0.2265*C+0.2265*SR-0.2265*SR
}
SoX: 1v0.3205,3v0.2265,4v0.2265,4v-0.2265 2v0.3205,3v0.2265,5v0.2265,5v-0.2265


function Dmix5Dpl2(clip a) # 5 Channels FL,LR,C,SL,SR
{
flr = GetChannel(a, 1, 2)
fcc = GetChannel(a, 3, 3)
lrc = MixAudio(flr, fcc, 0.3254, 0.2301)
// 0.3254*FL+0.2301*C 0.3254*FR+0.2301*C
bl = GetChannel(a, 4)
br = GetChannel(a, 5)
sl = MixAudio(bl, br, 0.2818, 0.1627)
// 0.2818*SL 0.1627*SR
sr = MixAudio(bl, br, -0.1627, -0.2818)
// -0.1627*SL -0.2818*SR
blr = MergeChannels(sl, sr)
//0.2818*SL+0.1627*SR -0.1627*SL-0.2818*SR
return MixAudio(lrc, blr, 1.0, 1.0)
//fl' = 0.3254*FL+0.2301*C+0.2818*SL+0.1627*SR
//fr' = 0.3254*FR+0.2301*C-0.1627*SL-0.2818*SR
}
SoX: 1v0.3254,3v0.2301,4v0.2818,5v0.1627 2v0.3254,3v0.2301,4v-0.1627,5v-0.2818

function Dmix6Stereo(clip a) # 6 Channels FL, FR, C, LFE, SL, SR
{
flr = GetChannel(a, 1, 2)
fcc = GetChannel(a, 3, 3)
lrc = MixAudio(flr, fcc, 0.3694, 0.2612)
//0.3694*FL+0.2612*C 0.3694*FR+0.2612*C
blr = GetChannel(a, 5, 6)
return MixAudio(lrc, blr, 1.0, 0.3694)
//0.3694*FL+0.2612*C+0.3694*SL 0.3694*FR+0.2612*C+0.3694*SR
}
SoX: 1v0.3694+3v0.2612+4v0.3694 2v0.3694+3v0.2612+5v0.3694

function Dmix6Dpl(clip a) # 6 Channels FL, FR, C, LFE, SL, SR
{
flr = GetChannel(a, 1, 2)
fcc = GetChannel(a, 3, 3)
lrc = MixAudio(flr, fcc, 0.3205, 0.2265)
//0.3205*FL+0.2265*C 0.3205*FR+0.2265*C
bl = GetChannel(a, 5)
br = GetChannel(a, 6)
sl = MixAudio(bl, br, 0.2265, 0.2265)
//0.2265*SL 0.2265*SR
sr = MixAudio(bl, br, -0.2265, -0.2265)
//-0.2265*SL -0.2265*SR
blr = MergeChannels(sl, sr)
//0.2265*SL-0.2265*SL 0.2265*SR-0.2265*SR
return MixAudio(lrc, blr, 1.0, 1.0)
//0.3205*FL+0.2265*C+0.2265*SL-0.2265*SL 0.3205*FR+0.2265*C+0.2265*SR-0.2265*SR
}
SoX: 1v0.3205,3v0.2265+4v0.2265-4v-0.2265 2v0.3205,3v0.2265+5v0.2265-5v-0.2265


function Dmix6Dpl2(clip a) # 6 Channels FL, FR, C, LFE, SL, SR
{
flr = GetChannel(a, 1, 2)
fcc = GetChannel(a, 3, 3)
lrc = MixAudio(flr, fcc, 0.3254, 0.2301)
//0.3254*FL+0.2301*C 0.3254*FR+0.2301*C
bl = GetChannel(a, 5)
br = GetChannel(a, 6)
sl = MixAudio(bl, br, 0.2818, 0.1627)
//0.2818*SL 1627*SR
sr = MixAudio(bl, br, -0.1627, -0.2818)
//-0.1627*SL -0.2818*SR
blr = MergeChannels(sl, sr)
//0.2818*SL-0.1627*SL 1627*SR-0.2818*SR
return MixAudio(lrc, blr, 1.0, 1.0)
//0.3254*FL+0.2301*C+0.2818*SL-0.1627*SL 0.3254*FR+0.2301*C+1627*SR-0.2818*SR
}
SoX: 1v0.3254,3v0.2301,5v0.2818,5v-0.1627 2v0.3254,3v0.2301,6v0.2818,6v-0.1627


function Dmix6StereoLfe(clip a) # 6 Channels FL, FR, C, LFE, SL, SR
{
flr = GetChannel(a, 1, 2)
fcc = GetChannel(a, 3, 3)
lrc = MixAudio(flr, fcc, 0.2929, 0.2071)
//0.2929*FL+0.2071*C 0.2929*FR+0.2071*C
lfe = GetChannel(a, 4, 4)
lrc = MixAudio(lrc, lfe, 1.0, 0.2071)
//0.2929*FL+0.2071*C+0.2071*SUB 0.2929*FR+0.2071*C+0.2071*SUB
blr = GetChannel(a, 5, 6)
return MixAudio(lrc, blr, 1.0, 0.2929)
//0.2929*FL+0.2071*C+0.2071*SUB+0.2929*SL 0.2929*FR+0.2071*C+0.2071*SUB+0.2929*SR
}
SoX: 1v0.2929,3v0.2071,4v0.2071,5v0.2929 2v0.2929,3v0.2071,4v0.2071,6v0.2929

function Dmix6DplLfe(clip a) # 6 Channels FL, FR, C, LFE, SL, SR
{
flr = GetChannel(a, 1, 2)
fcc = GetChannel(a, 3, 3)
lrc = MixAudio(flr, fcc, 0.2613, 0.1847)
//0.2613*FL+0.1847*C 0.2613*FR+0.1847*C
lfe = GetChannel(a, 4, 4)
lrc = MixAudio(lrc, lfe, 1.0, 0.1847)
//0.2613*FL+0.1847*C+0.1847*SUB 0.2613*FR+0.1847*C+0.1847*SUB
bl = GetChannel(a, 5)
br = GetChannel(a, 6)
sl = MixAudio(bl, br, 0.1847, 0.1847)
//0.1847*SL 0.1847*SR
sr = MixAudio(bl, br, -0.1847, -0.1847)
//-0.1847*SL -0.1847*SR
blr = MergeChannels(sl, sr)
//0.1847*SL-0.1847*SL 0.1847*SR-0.1847*SR
return MixAudio(lrc, blr, 1.0, 1.0)
//0.2613*FL+0.1847*C+0.1847*SUB+0.1847*SL-0.1847*SL 0.2613*FR+0.1847*C+0.1847*SUB+0.1847*SR-0.1847*SR
}
SoX: 1v0.2613,3v0.1847,4v0.1847,5v0.1847,5v-0.1847 2v0.2613,3v0.1847,4v0.1847,6v0.1847,6v-0.1847

function Dmix6Dpl2Lfe(clip a) # 6 Channels FL, FR, C, LFE, SL, SR
{
flr = GetChannel(a, 1, 2)
fcc = GetChannel(a, 3, 3)
lrc = MixAudio(flr, fcc, 0.2646, 0.1870)
// 0.2646*FL+0.1870*C 0.2646FR+0.1870*C
lfe = GetChannel(a, 4, 4)
lrc = MixAudio(lrc, lfe, 1.0, 0.1870)
// 0.2646*FL+0.1870*C+SUB*0.1870 0.2646*FR+0.1870*C+SUB*0.1870
bl = GetChannel(a, 5)
br = GetChannel(a, 6)
sl = MixAudio(bl, br, 0.2291, 0.1323)
// 0.2291*SL 0.1323*SR
sr = MixAudio(bl, br, -0.1323, -0.2291)
// -0.1323*SL -0.2291*SR
blr = MergeChannels(sl, sr)
// 0.2291*SL+0.1323*SR -0.1323*SL-0.2291*SR

return MixAudio(lrc, blr, 1.0, 1.0)
//fl' = 0.2646*FL+0.1870*C+SUB*0.1870+0.2291*SL+0.1323*SR
//fr' = 0.2646*FR+0.1870*C+SUB*0.1870-0.1323*SL-0.2291*SR
}
SoX: 1v0.2646,3v0.1870,4v0.1870,5v0.2991,6v0.1323 2v0.2646,3v0.1870,4v0.1870,5v-0.1323,6v-0.2291

Brazil2
13th January 2010, 18:27
Of course you can use other coeficients for dpl I or simple stereo or add LFE to mix.
So what coefficients are you suggesting for a simple stereo downmix ? (not DPL I or II)
I mean playing a 5.1 or 7.1 audio track on a computer with stereo speakers only.

tebasuna51
14th January 2010, 00:50
So what coefficients are you suggesting for a simple stereo downmix ? (not DPL I or II)
I mean playing a 5.1 or 7.1 audio track on a computer with stereo speakers only.
You have the answer in the precedent post:

function Dmix6Stereo(clip a) # 6 Channels FL, FR, C, LFE, SL, SR
{
flr = GetChannel(a, 1, 2)
fcc = GetChannel(a, 3, 3)
lrc = MixAudio(flr, fcc, 0.3694, 0.2612)
//0.3694*FL+0.2612*C 0.3694*FR+0.2612*C
blr = GetChannel(a, 5, 6)
return MixAudio(lrc, blr, 1.0, 0.3694)
//0.3694*FL+0.2612*C+0.3694*SL 0.3694*FR+0.2612*C+0.3694*SR
}
SoX: 1v0.3694+3v0.2612+4v0.3694 2v0.3694+3v0.2612+5v0.3694

Selur
14th January 2010, 10:14
I'm a bit confused about all the dpl downmixes :), e.g.

function Dmix5Dpl(clip a) # 5 Channels L,R,C,SL,SR
{
flr = GetChannel(a, 1, 2)
fcc = GetChannel(a, 3, 3)
lrc = MixAudio(flr, fcc, 0.3205, 0.2265)
//0.3205*FL+0.2265*C 0.3205*FR+0.2265*C
bl = GetChannel(a, 4)
br = GetChannel(a, 5)
sl = MixAudio(bl, br, 0.2265, 0.2265)
//0.2265*SL 0.2265*SR
sr = MixAudio(bl, br, -0.2265, -0.2265)
//-0.2265*SL -0.2265*SR
blr = MergeChannels(sl, sr)
//0.2265*SL-0.2265*SL 0.2265*SR-0.2265*SR
return MixAudio(lrc, blr, 1.0, 1.0)
//0.3205*FL+0.2265*C+0.2265*SL-0.2265*SL 0.3205*FR+0.2265*C+0.2265*SR-0.2265*SR
}
SoX: 1v0.3205,3v0.2265,4v0.2265,4v-0.2265 2v0.3205,3v0.2265,5v0.2265,5v-0.2265


wouldn't something like: 4v0.2265,4v-0.2265 result in no change?
I suspect I should have used another SoX open to represent the negative values or I just don't get what the mean. :)

Cu Selur

tebasuna51
14th January 2010, 11:37
I'm a bit confused about all the dpl downmixes :), e.g.

function Dmix5Dpl(clip a) # 5 Channels L,R,C,SL,SR
...
sl = MixAudio(bl, br, 0.2265, 0.2265)
//0.2265*SL 0.2265*SR
sr = MixAudio(bl, br, -0.2265, -0.2265)
//-0.2265*SL -0.2265*SR
blr = MergeChannels(sl, sr)
//0.2265*SL-0.2265*SL 0.2265*SR-0.2265*SR
return MixAudio(lrc, blr, 1.0, 1.0)
//0.3205*FL+0.2265*C+0.2265*SL-0.2265*SL 0.3205*FR+0.2265*C+0.2265*SR-0.2265*SR
}
SoX: 1v0.3205,3v0.2265,4v0.2265,4v-0.2265 2v0.3205,3v0.2265,5v0.2265,5v-0.2265


wouldn't something like: 4v0.2265,4v-0.2265 result in no change?
Sorry, I don't verify all functions, mergechannels sl, sr is:

blr = MergeChannels(sl, sr)
//0.2265*SL+0.2265*SR -0.2265*SL-0.2265*SR
return MixAudio(lrc, blr, 1.0, 1.0)
//0.3205*FL+0.2265*C+0.2265*SL+0.2265*SR 0.3205*FR+0.2265*C-0.2265*SL-0.2265*SR
}
SoX: 1v0.3205,3v0.2265,4v0.2265,5v0.2265 2v0.3205,3v0.2265,4v-0.2265,5v-0.2265

Selur
14th January 2010, 11:40
okay, that solves my confusion
Thanks again ! :)

all the functions are ment to be symetric:
sl = MixAudio(bl, br, 0.2291, 0.1323)
// 0.2291*SL 0.1323*SR
sr = MixAudio(bl, br, -0.1323, -0.2291)
// -0.1323*SL -0.2291*SR
blr = MergeChannels(sl, sr)
// 0.2291*SL+0.1323*SR -0.1323*SL-0.2291*SR
should then be:
sl = MixAudio(bl, br, 0.2291, 0.2291)
// 0.2291*SL 0.2291*SR
sr = MixAudio(bl, br, -0.1323, -0.1323
// -0.1323*SL -0.1323*SR
blr = MergeChannels(sl, sr)
// 0.2291*SL-0.1323*SR 0.2291*SR-0.1323*SL
right ?

tebasuna51
14th January 2010, 13:06
all the functions are ment to be symetric:
sl = MixAudio(bl, br, 0.2291, 0.1323)
// 0.2291*SL 0.1323*SR
sr = MixAudio(bl, br, -0.1323, -0.2291)
// -0.1323*SL -0.2291*SR
blr = MergeChannels(sl, sr)
// 0.2291*SL+0.1323*SR -0.1323*SL-0.2291*SR
is a correct Dolby ProLogic II mix (recover 5.0)
should then be:
sl = MixAudio(bl, br, 0.2291, 0.2291)
// 0.2291*SL+0.2291*SR (1 channel)
sr = MixAudio(bl, br, -0.1323, -0.1323)
// -0.1323*SL-0.1323*SR (1 channel)
blr = MergeChannels(sl, sr)
// 0.2291*SL-0.1323*SR, 0.2291*SR-0.1323*SL (2 channels)
right ?
wrong, the result is:

// 0.2291*SL+0.2291*SR, -0.1323*SR-0.1323*SL
and this isn't a correct mix, isn't stereo, isn't dpl, isn't dpl II

Remember:
MixAudio take 2 audios (with 1 or more channels each one) and return only a mixed one audio.
MergeChannels take 2 (or more) channels and return a multichannel audio without mix.

Selur
14th January 2010, 13:08
DOH, I misunderstood the MixAudio :)

MixAudio take 2 (or more) channels and return only a mixed one.
this would mean for 3toStereo
function Dmix3Stereo(clip a) # 3 Channels L,R,C or L,R,S
{
flr = GetChannel(a, 1, 2)
//FL FR (2 channel)
fcc = GetChannel(a, 3, 3)
//C C (2 channel)
return MixAudio(flr, fcc, 0.5858, 0.4142)
//0.5858*FL+0.4142*C 0.5858*FR+0.4142*C
}
-> MixAudio returns a two channel stream since it was fed with two 2 channel inputs

Selur
14th January 2010, 14:56
So is this right:function Dmix5Dpl(clip a) # 5 Channels L,R,C,SL,SR
{
flr = GetChannel(a, 1, 2) //FL FR (2 channel)
fcc = GetChannel(a, 3, 3) //C C(2 channel)
lrc = MixAudio(flr, fcc, 0.3205, 0.2265) //0.3205*FL+0.2265*C 0.3205*FR+0.2265*C
bl = GetChannel(a, 4) //SL (1 channel)
br = GetChannel(a, 5) //SR (1 channel)
sl = MixAudio(bl, br, 0.2265, 0.2265) //0.2265*SL+0.2265*SR (1 channel)
sr = MixAudio(bl, br, -0.2265, -0.2265) //-0.2265*SL-0.2265*SR (1 channel)
blr = MergeChannels(sl, sr) //0.2265*SL+0.2265*SR -0.2265*SL-0.2265*SR (2 channel)
return MixAudio(lrc, blr, 1.0, 1.0) //0.3205*FL+0.2265*C+0.2265*SL+0.2265*SR 0.3205*FR+0.2265*C-0.2265*SL-0.2265*SR (2 channel)
}... still uncertain about the MergeChannels function ;)

Selur
22nd March 2010, 18:22
Finally found the time and motivation to try to convert one of NorthPole's (http://forum.doom9.org/showthread.php?p=787216#post787216) BeHappy UpMix functions to sox.
Function to be converted: <Option>
<Name>Audio with a mix of sounds (ie. Action, Adventure)</Name>
<Value>
# Profile to use with audio sources that have a wider range of sound content. 20ms delay and -3db attenuation on surround
# Note: General purpose profile
front_{2} = stereo_{2}.soxfilter("filter 20-20000")
back_{2} = stereo_{2}.soxfilter("filter 100-7000")
fl_{2} = mixaudio(front_{2}.GetLeftChannel(),front_{2}.GetRightChannel(),0.668,-0.668)
fr_{2} = mixaudio(front_{2}.GetRightChannel(),front_{2}.GetLeftChannel(),0.668,-0.668)
cc_{2} = mixaudio(mixaudio(front_{2}.GetLeftChannel(),fl_{2},1,-1),mixaudio(front_{2}.GetRightChannel(),fr_{2},1,-1),0.398,0.398)
lfe_{2} = ConvertToMono(stereo_{2}).SoxFilter("lowpass 120","vol -0.447")
sl_{2} = mixaudio(back_{2}.GetLeftChannel(),back_{2}.GetRightChannel(),0.473,-0.473)
sr_{2} = mixaudio(back_{2}.GetRightChannel(),back_{2}.GetLeftChannel(),0.473,-0.473)
sl_{2} = DelayAudio(sl_{2},0.02)
sr_{2} = DelayAudio(sr_{2},0.02)
</Value>
</Option>
<Option>


Me trying to convert it:
#input to wav
mplayer -ao pcm input.mp3 -ao pcm:file="dump.wav"

#resample to 48kHz and lower volume to avaid clipping
sox -S -V -c 2 dump.wav -r 48k stereoInput.wav gain -h

#front = stereo.soxfilter("filter 20-20000")
sox -S -V -c 2 stereoInput.wav front.wav sinc 20-20000
sox -S -V -c 2 front.wav -c 1 frontL.wav mixer -l
sox -S -V -c 2 front.wav -c 1 frontR.wav mixer -r

#fl = mixaudio(front.GetLeftChannel(),front.GetRightChannel(),0.794,-0.794)
sox -S -V -c 2 front.wav front_left.wav remix -m 1v0.794,2v-0.794

#fr = mixaudio(front.GetRightChannel(),front.GetLeftChannel(),0.794,-0.794)
sox -S -V -c 2 front.wav front_right.wav remix -m 2v0.794,1v-0.794

#rear = stereo.soxfilter("filter 100-7000")
sox -S -V -c 2 stereoInput.wav rear.wav sinc 100-7000

#sl = mixaudio(rear.GetLeftChannel(),rear.GetRightChannel(),0.562,-0.562)
#sl = DelayAudio(sl,0.02)
sox -S -V -c 2 rear.wav rear_left.wav remix -m 1v0.562,2v-0.562 delay 0.02

#sr = mixaudio(rear.GetRightChannel(),rear.GetLeftChannel(),0.562,-0.562)
#sr = DelayAudio(sr,0.02)
sox -S -V -c 2 rear.wav rear_right.wav remix -m 1v0.562,2v-0.562 delay 0.02

#cc = mixaudio(mixaudio(front.GetLeftChannel(),fl,1,-1),mixaudio(front.GetRightChannel(),fr,1,-1),0.224,0.224)
# = mixaudio(cc_l, cc_r, 0.224,0.224)
#cc_l(1) = mixaudio(front.GetLeftChannel(),fl,1,-1)
#cc_r(1) = mixaudio(front.GetRightChannel(),fr,1,-1)
sox -S -V -M frontL.wav front_left.wav centerL.wav remix -m 1v0.224,2v-0.224
sox -S -V -M frontR.wav front_right.wav centerR.wav remix -m 1v0.224,2v-0.224
sox -S -V -m centerL.wav centerR.wav center.wav

#lfe = ConvertToMono(stereo).SoxFilter("lowpass 120","vol -0.596")
sox -S -V -v -0.596 stereoInput.wav -c 1 lfe.wav lowpass 120 remix -

#merge channels
sox -S -V -M front_left.wav front_right.wav rear_left.wav rear_right.wav center.wav lfe.wav multichannel.wav

#normalize + making sure it's 16bit
sox -S -V -G multichannel.wav -b 16 normalize.wav

#convert
neroAacEnc -if normalize.wav -br 196k -ignorelength -of "test.mp4"

Hope someone understands my go at it, can verify it and help if it's wrong. (I'm pretty sure this should be possible with less intermediate files,... :))

Cu Selur

b66pak
22nd March 2010, 21:17
thanks...
_

Selur
24th March 2010, 09:44
typo: sox -S -V -v 0.596 stereoInput.wav -c 1 lfe.wav lowpass 120 remix
needs to be: sox -S -V -v -0.596 stereoInput.wav -c 1 lfe.wav lowpass 120 remix
-> fixed above

Selur
24th March 2010, 10:40
I tried to 'translate' the other profiles too, so here are all the profiles:

#Source: http://forum.doom9.org/showthread.php?p=787216#post787216)

##
# TITLE:
# Audio with mostly dialog (ie. Comedy, Drama)
##

#input to wav
mplayer -ao pcm input.mp3 -ao pcm:file="dump.wav"

#resample to 48kHz and lower volume to avaid clipping
sox -S -V -c 2 dump.wav -r 48k stereoInput.wav gain -h

#front = stereo.soxfilter("filter 20-20000")
sox -S -V -c 2 stereoInput.wav front.wav sinc 20-20000
sox -S -V -c 2 front.wav -c 1 frontL.wav mixer -l
sox -S -V -c 2 front.wav -c 1 frontR.wav mixer -r

#fl = mixaudio(front.GetLeftChannel(),front.GetRightChannel(),0.794,-0.794)
sox -S -V -c 2 front.wav front_left.wav remix -m 1v0.794,2v-0.794

#fr = mixaudio(front.GetRightChannel(),front.GetLeftChannel(),0.794,-0.794)
sox -S -V -c 2 front.wav front_right.wav remix -m 2v0.794,1v-0.794

#rear = stereo.soxfilter("filter 100-7000")
sox -S -V -c 2 stereoInput.wav rear.wav sinc 100-7000

#sl = mixaudio(rear.GetLeftChannel(),rear.GetRightChannel(),0.562,-0.562)
#sl = DelayAudio(sl,0.02)
sox -S -V -c 2 rear.wav rear_left.wav remix -m 1v0.562,2v-0.562 delay 0.02

#sr = mixaudio(rear.GetRightChannel(),rear.GetLeftChannel(),0.562,-0.562)
#sr = DelayAudio(sr,0.02)
sox -S -V -c 2 rear.wav rear_right.wav remix -m 1v0.562,2v-0.562 delay 0.02

#cc = mixaudio(mixaudio(front.GetLeftChannel(),fl,1,-1),mixaudio(front.GetRightChannel(),fr,1,-1),0.224,0.224)
# = mixaudio(cc_l, cc_r, 0.224,0.224)
#cc_l(1) = mixaudio(front.GetLeftChannel(),fl,1,-1)
#cc_r(1) = mixaudio(front.GetRightChannel(),fr,1,-1)
sox -S -V -M frontL.wav front_left.wav centerL.wav remix -m 1v0.224,2v-0.224
sox -S -V -M frontR.wav front_right.wav centerR.wav remix -m 1v0.224,2v-0.224
sox -S -V -m centerL.wav centerR.wav center.wav

#lfe = ConvertToMono(stereo).SoxFilter("lowpass 120","vol -0.596")
sox -S -V -v -0.596 stereoInput.wav -c 1 lfe.wav lowpass 120 remix -

#merge channels
sox -S -V -M front_left.wav front_right.wav rear_left.wav rear_right.wav center.wav lfe.wav multichannel.wav

#normalize + making sure it's 16bit
sox -S -V -G multichannel.wav -b 16 normalize.wav

#convert
neroAacEnc -if normalize.wav -br 196k -ignorelength -of "dialog.mp4"



##
# TITLE:
# Audio with a mix of sounds (ie. Action, Adventure)(http://forum.doom9.org/showthread.php?p=787216#post787216)
##

#input to wav
mplayer -ao pcm input.mp3 -ao pcm:file="dump.wav"

#resample to 48kHz and lower volume to avaid clipping
sox -S -V -c 2 dump.wav -r 48k stereoInput.wav gain -h

#front = stereo.soxfilter("filter 20-20000")
sox -S -V -c 2 stereoInput.wav front.wav sinc 20-20000
sox -S -V -c 2 front.wav -c 1 frontL.wav mixer -l
sox -S -V -c 2 front.wav -c 1 frontR.wav mixer -r

#fl = mixaudio(front.GetLeftChannel(),front.GetRightChannel(),0.668,-0.668)
sox -S -V -c 2 front.wav front_left.wav remix -m 1v0.668,2v-0.668

#fr = mixaudio(front.GetRightChannel(),front.GetLeftChannel(),0.668,-0.668)
sox -S -V -c 2 front.wav front_right.wav remix -m 2v0.668,1v-0.668

#rear = stereo.soxfilter("filter 100-7000")
sox -S -V -c 2 stereoInput.wav rear.wav sinc 100-7000

#sl = mixaudio(rear.GetLeftChannel(),rear.GetRightChannel(),0.473,-0.473)
#sl = DelayAudio(sl,0.02)
sox -S -V -c 2 rear.wav rear_left.wav remix -m 1v0.473,2v-0.473 delay 0.02

#sr = mixaudio(rear.GetRightChannel(),rear.GetLeftChannel(),0.473,-0.473)
#sr = DelayAudio(sr,0.02)
sox -S -V -c 2 rear.wav rear_right.wav remix -m 1v0.473,2v-0.473 delay 0.02

#cc = mixaudio(mixaudio(front.GetLeftChannel(),fl,1,-1),mixaudio(front.GetRightChannel(),fr,1,-1),0.398,0.398)
# = mixaudio(cc_l, cc_r, 0.398,0.398)
#cc_l(1) = mixaudio(front.GetLeftChannel(),fl,1,-1)
#cc_r(1) = mixaudio(front.GetRightChannel(),fr,1,-1)
sox -S -V -M frontL.wav front_left.wav centerL.wav remix -m 1v0.398,2v-0.398
sox -S -V -M frontR.wav front_right.wav centerR.wav remix -m 1v0.398,2v-0.398
sox -S -V -m centerL.wav centerR.wav center.wav

#lfe = ConvertToMono(stereo).SoxFilter("lowpass 120","vol -0.447")
sox -S -V -v -0.447 stereoInput.wav -c 1 lfe.wav lowpass 120 remix -

#merge channels
sox -S -V -M front_left.wav front_right.wav rear_left.wav rear_right.wav center.wav lfe.wav multichannel.wav

#normalize + making sure it's 16bit
sox -S -V -G multichannel.wav -b 16 normalize.wav

#convert
neroAacEnc -if normalize.wav -br 196k -ignorelength -of "action.mp4"



##
# TITLE:
# Grezen Profile
##

#input to wav
mplayer -ao pcm input.mp3 -ao pcm:file="dump.wav"

#resample to 48kHz and lower volume to avaid clipping
sox -S -V -c 2 dump.wav -r 48k stereoInput.wav gain -h

#front = stereo.soxfilter("filter 20-20000")
sox -S -V -c 2 stereoInput.wav front.wav sinc 20-20000
sox -S -V -c 2 front.wav -c 1 frontL.wav mixer -l gain -h
sox -S -V -c 2 front.wav -c 1 frontR.wav mixer -r gain -h

#fl = mixaudio(front.GetLeftChannel(),front.GetRightChannel(),0.885,-0.115)
sox -S -V -c 2 front.wav front_left.wav gain -h remix -m 1v0.885,-,2v-0.115

#fr = mixaudio(front.GetRightChannel(),front.GetLeftChannel(),0.885,-,-0.115)
sox -S -V -c 2 front.wav front_right.wav gain -h remix -m 2v0.885,-,1v-0.115

#rear = stereo.soxfilter("filter 100-7000")
sox -S -V -c 2 stereoInput.wav rear.wav sinc 100-7000

#sl = mixaudio(rear.GetLeftChannel(),rear.GetRightChannel(),0.668,-0.668)
#sl = DelayAudio(sl,0.02)
sox -S -V -c 2 rear.wav rear_left.wav remix -m 1v0.668,2v-0.668 delay 0.02

#sr = mixaudio(rear.GetRightChannel(),rear.GetLeftChannel(),0.668,-0.668)
#sr = DelayAudio(sr,0.02)
sox -S -V -c 2 rear.wav rear_right.wav remix -m 1v0.668,2v-0.668 delay 0.02

#cc = mixaudio(front.GetRightChannel(),front.GetLeftChannel,0.4511,0.4511)
sox -S -V -M frontR.wav frontL.wav center.wav remix -m 1v0.4511,2v0.4511

#lfe = ConvertToMono(stereo).SoxFilter("lowpass 120","vol -0.5")
sox -S -V -v -0.5 stereoInput.wav -c 1 lfe.wav lowpass 120 remix -

#merge channels
sox -S -V -M front_left.wav front_right.wav rear_left.wav rear_right.wav center.wav lfe.wav multichannel.wav

#normalize + making sure it's 16bit
sox -S -V -G multichannel.wav -b 16 normalize.wav

#convert
neroAacEnc -if normalize.wav -br 196k -ignorelength -of "grezen.mp4"



##
# TITLE:
# Farina Profile
##

#input to wav
mplayer -ao pcm input.mp3 -ao pcm:file="dump.wav"

#resample to 48kHz and lower volume to avaid clipping
sox -S -V -c 2 dump.wav -r 48k stereoInput.wav gain -h

#front = stereo.soxfilter("filter 20-20000")
sox -S -V -c 2 stereoInput.wav front.wav sinc 20-20000
sox -S -V -c 2 front.wav -c 1 frontL.wav mixer -l
sox -S -V -c 2 front.wav -c 1 frontR.wav mixer -r
sox -S -V -M frontL.wav frontR.wav frontLR.wav remix -m 1v0.5,2v0.5
sox -S -V -M frontL.wav frontR.wav frontRL.wav remix -m 1v0.5,2v-0.5

#fl = mixaudio(mixaudio(front.GetLeftChannel(),front.GetRightChannel(),0.500,0.500),mixaudio(front_
sox -S -V -M frontLR.wav frontRL.wav front_left.wav remix -m 1v0.8125,2v1.1875

#fr = mixaudio(mixaudio(front.GetLeftChannel(),front.GetRightChannel(),0.500,0.500),mixaudio(front_
sox -S -V -M frontLR.wav frontRL.wav front_left.wav remix -m 1v0.8125,2v-1.1875

#rear = stereo.soxfilter("filter 100-7000")
sox -S -V -c 2 stereoInput.wav rear.wav sinc 100-7000

#sl = mixaudio(rear.GetLeftChannel(),rear.GetRightChannel(),0.668,-0.668)
#sl = DelayAudio(sl,0.02)
sox -S -V -c 2 rear.wav rear_left.wav remix -m 1v0.668,2v-0.668 delay 0.02

#sr = mixaudio(rear.GetRightChannel(),rear.GetLeftChannel(),0.668,-0.668)
#sr = DelayAudio(sr,0.02)
sox -S -V -c 2 rear.wav rear_right.wav remix -m 1v0.668,2v-0.668 delay 0.02

#cc = mixaudio(mixaudio(front.GetLeftChannel(),fl,1,-1),mixaudio(front.GetRightChannel(),fr,1,-1),0.375,0.375)
# = mixaudio(cc_l, cc_r, 0.375,0.375)
#cc_l(1) = mixaudio(front.GetLeftChannel(),fl,1,-1)
#cc_r(1) = mixaudio(front.GetRightChannel(),fr,1,-1)
sox -S -V -M frontL.wav front_left.wav centerL.wav remix -m 1v0.375,2v-0.375
sox -S -V -M frontR.wav front_right.wav centerR.wav remix -m 1v0.375,2v-0.375
sox -S -V -m centerL.wav centerR.wav center.wav

#lfe = ConvertToMono(stereo).SoxFilter("lowpass 120","vol -0.5")
sox -S -V -v -0.5 stereoInput.wav -c 1 lfe.wav lowpass 120 remix -

#merge channels
sox -S -V -M front_left.wav front_right.wav rear_left.wav rear_right.wav center.wav lfe.wav multichannel.wav

#normalize + making sure it's 16bit
sox -S -V -G multichannel.wav -b 16 normalize.wav

#convert
neroAacEnc -if normalize.wav -br 196k -ignorelength -of "farina.mp4"

Would be cool if some people with surround systems could check the different profiles and post if they sound alright. :)

Cu Selur

Selur
1st February 2012, 09:05
Does anyone know how to do:
6.1 and 7.1 -> 5.1
6.1 and 7.1 -> Stereo
6.1 and 7.1 -> Stereo (dpl)
6.1 and 7.1 -> Stereo (dpl2)
6.1 and 7.1 -> Stereo (lfe)
6.1 and 7.1 -> Stereo (dpllfe)
6.1 and 7.1 -> Stereo (dpl2lfe)
with sox?

I guess:
6.1toStereo: "1v0.3694,3v0.2612,5v0.1847,7v0.1847 2v0.3694,3v0.2612,5v0.1847,7v0.1847"
6.1toStereo (dpl): "1v0.3205,3v0.2265,4v0.2265,5v0.1133,7v0.1132 2v0.3205,3v0.2265,4v-0.2265,6v-0.1133,7v-0.1132"
6.1toStereo (dpl2): "1v0.3254,3v0.2301,5v0.1414,6v0.814,7v0.2222 2v0.3254,3v0.2301,5v-0.814,6v-0.1414,7v-0.2222"
6.1toStereo (lfe): "1v0.2929,3v0.2071,4v0.2071,5v0.1465,7v1464 2v0.2929,3v0.2071,4v0.2071,6v0.1465,7v1464"
6.1toStereo (dpllfe): "1v0.2613,3v0.1847,4v0.1847,5v0.0936,6v0.0935,7v0.1847 2v0.2613,3v0.1847,4v0.1847,5v-0.0935,6v-0.0936,7v-0.1847"
6.1toStereo (dpl2lfe): "1v0.2646,3v0.1870,4v0.1870,5v0.1146,6v0.0661,7v0.1807 2v0.2646,3v0.1870,4v0.1870,5v-0.0662,6v-0.1146,7v-0.1807"
6.1to5.1: "1v 2v 3v 4v 5v0.5,7v0.5 6v0.5,7v0.5" would just be too easy ;)
=> Okay, forget that seems like the 7th channel audio is already included in the SL&SR channel, so just ignoring it and using th 5.1 downmix calls should be fine :)

Cu Selur

moytrage
5th April 2013, 07:43
This Dolby ProLogic II downmix:
fl' = 0.3254xFL + 0.2301xC + 0.2818xSL + 0.1627xSR
fr' = 0.3254xFR + 0.2301xC - 0.1627xSL - 0.2818xSR

Can be implemented with SoX (and normalized) like:
sox 6w321.wav 2dpl.wav remix -m 1v0.3254,3v0.2301,5v0.2818,6v0.1627 2v0.3254,3v0.2301,5v-0.1627,6v-0.2818 norm

According to HandBrake's source code https://trac.handbrake.fr/browser/tags/0.9.8/libhb/downmix.c#L698 (channels order in a column is FC,FL,FR,BL,BR...) downmixing is done through this formula:
fl' = 0.3254xFL + 0.2301xC - 0.2818xSL - 0.1627xSR
fr' = 0.3254xFR + 0.2301xC + 0.1627xSL + 0.2818xSR
Which has opposite signs for L/R two last additives. Or am I wrong? Also same signs has a formula given at the end of http://en.wikipedia.org/wiki/Dolby_Pro_Logic, except for a bit different coefficients (sqrt(19/25) instead of sqrt(3/4)).
BTW, what's the correct way to translate complex coefficients to linear real form in this case if someone knows?
To conclude, a full formula in symbolic form would be:
fl' = (1 * FL + sqrt(1/2) * C - sqrt(3/4) * SL - sqrt(1/4) * SR)/(1 + sqrt(1/2) + sqrt(3/4) + sqrt(1/4)),
fr' = (1 * FL + sqrt(1/2) * C + sqrt(1/4) * SL + sqrt(3/4) * SR)/(1 + sqrt(1/2) + sqrt(3/4) + sqrt(1/4)). Which gives a final sox command: sox 6w321.wav 2dpl.wav remix -m 1v0.3254,3v0.2301,5v-0.2818,6v-0.1627 2v0.3254,3v0.2301,5v0.1627,6v0.2818 norm. Correct me if I wrong.

tebasuna51
5th April 2013, 13:44
...
Correct me if I wrong.

That was discussed several times in this forum.
The exact coeficients, the signs, ...

http://forum.doom9.org/showthread.php?t=57988
http://forum.doom9.org/showthread.php?t=112122

I still recommend the downmix I put, but maybe I'm wrong.

Jenyok
6th April 2013, 06:54
Algorithm to convert real stereo audio clip to 5.1 audio clip.
.

#
# Algorithm to convert real stereo audio clip to 5.1 audio clip
#
# Input audio clip must be minimum 96 kHz / 24 bits integer real stereo audio clip
#
# All Temporary variables of audio clip in algorithm must be 32 bits integer stereo or mono audio clip
#
# All Output audio clips must be 24 bits integer mono audio clips
#



Input # Input must be stereo audio signal 96 kHz / 24 bits
Input = Normalize(Input, 1.0) # Normalize audio signal Input to +0dB


LR = Normalize(Input, 0.251) # Normalize audio signal LR to -12dB, stereo
LR = ConvertAudioTo32bit(LR) # Resolution LR 32bits, -12dB, stereo


LRm = FFT_HighPass_Filter(LR, 200) # FAST FOURIER TRANSFORM High Pass Filter "/----" 200Hz to LRm, -12dB, stereo
LRm = ConvertAudioTo32bit(LRm) # Resolution LRm 32 bits, -12dB, stereo


# Subwoofer channel
#
LFE = MixAudio(LR, LRm, 1.0, -1.0) # LFE = LR - LRm, 32 bits, stereo
# or maybe so
#LFE = FFT_LowPass_Filter(LR, 200) # FAST FOURIER TRANSFORM Low Pass Filter "----\" 200Hz to LFE, -12dB, stereo

LFE = ConvertAudioTo32bit(LFE) # Resolution LFE 32 bits, -12dB, stereo
LFE = AmplifyDB(LFE, +9) # Amplify relative audio signal LFE on +9dB (-12dB +9dB), 32 bits, stereo

LFEl = GetChannels(LFE, 1) # Get left audio channel from audio signal LFE, 32 bits, stereo
LFEl = ConvertToMono(LFEl) # Convert audio signal LFEl, 32 bits, mono
LFEr = GetChannels(LFE, 2) # Get right audio channel from audio signal LFE, 32 bits, stereo
LFEr = ConvertToMono(LFEr) # Convert audio signal LFEr, 32 bits, mono

LFE = MixAudio(LFEl, LFEr, 0.5, 0.5) # LFE = LFEl + LFEr, 32 bits, stereo
LFE = ConvertToMono(LFE) # Convert audio signal LFE, 32 bits, mono
LFE = SHIFTPHASE(LFE, +90, 200) # Shift LFE phase audio signal to +90 grad, frequency 200Hz, 32 bits, mono
LFE = ConvertAudioTo24bit(LFE) # Resolution LFE 24 bits, mono


# Central channel
#
C = Normalize(LRm, 0.707) # Normalize audio signal C to -3dB, 32 bits, stereo
C = ConvertAudioTo32bit(C) # Resolution C 32 bits, -3dB, stereo

Cl = GetChhanel(C, 1) # Get left audio channel from audio signal C, 32 bits, stereo
Cl = ConvertToMono(Cl) # Convert audio signal Cl, 32 bits, mono
Cr = GetChhanel(C, 2) # Get right audio channel from audio signal C, 32 bits, stereo
Cr = ConvertToMono(Cr) # Convert audio signal Cr, 32 bits, mono

C = MixAudio(Cl, Cr, 0.5, 0.5) # C = 0.707 * Cl + 0.707 * Cr, 32 bits, mono
C = ConvertToMono(C) # Convert audio signal C, 32 bits, mono
C = AmplifyDB(C, +3) # Amplify relative audio signal C on +3dB, 32 bits, mono
C = ConvertAudioTo24bit(C) # Resolution C 24 bits, mono


# Front channels preliminary
#
Lc = GetChhanel(LRm, 1) # Get left audio channel from audio signal LRm, -12dB, 32 bits, stereo
Lc = ConvertToMono(Lc) # Convert audio signal Lc, -12dB, 32 bits, mono
Rc = GetChhanel(LRm, 2) # Get right audio channel from audio signal LRm, -12dB, 32 bits, stereo
Rc = ConvertToMono(Rc) # Convert audio signal Rc, -12dB, 32 bits, mono
NLc1 = MixAudio(Lc, Rc, 0.99, -0.33) # NLc1 = 1.5 * Lc - 0.5 * Rc, 32 bits, mono
NRc1 = MixAudio(Rc, Lc, 0.99, -0.33) # NRc1 = 1.5 * Rc - 0.5 * Lc, 32 bits, mono
LfRf = MergeChannels(NLc1, NRc1) # Merge channels NLc1, NRc1 to stereo singal LfRf, 32 bits, stereo
LfRf = ConvertAudioTo32bit(LfRf) # Resolution LfRf 32 bits, stereo
LfRf = AmplifyDB(LfRf, +3.61) # Amplify relative audio signal LfRf on +3.61dB, 32 bits, stereo


# Rear channels
#
LRm_reverb = REVERB(LRm, "Concert Hall Light") # Reverberation "Concert Hall Light, No combine source Left and Right", 32 bits stereo
LRm_reverb = ConvertAudioTo32bit(LRm_reverb) # Resolution LRm_reverb 32 bits, stereo
LRm_reverb = MixAudio(LRm_reverb, LRm, 1.0, -1.0) # LRm_reverb = LRm_reverb - LRm, 32 bits, stereo
LRm_reverb = AmplifyDB(LRm_reverb, +6) # Amplify relative audio signal LRm_reverb on +6dB, 32 bits, stereo
Ls = GetChhanel(LRm_reverb, 1) # Get left audio channel from audio signal LRm_reverb, 32 bits, stereo
Ls = ConvertToMono(Ls) # Convert audio signal Ls, 32 bits, mono
Ls = ConvertAudioTo24bit(Ls) # Resolution Ls 24 bits, mono
Rs = GetChhanel(LRm_reverb, 2) # Get right audio channel from audio signal LRm_reverb, 32 bits, stereo
Rs = ConvertToMono(Rs) # Convert audio signal Rs, 32 bits, mono
Rs = ConvertAudioTo24bit(Rs) # Resolution Rs 24 bits, mono


# Front channels
#
LfRf = MixAudio(LfRf, LRm_reverb, 1.0, -1.0) # LfRf = LfRf - LRm_reverb, 32 bits, stereo
Lf = GetChhanel(LfRf, 1) # Get left audio channel from audio signal LfRf, 32 bits, stereo
Lf = ConvertToMono(Lf) # Convert audio signal Lf, 32 bits, mono
Lf = ConvertAudioTo24bit(Lf) # Resolution Lf 24 bits, mono
Rf = GetChhanel(LfRf, 2) # Get right audio channel from audio signal LfRf, 32 bits, stereo
Rf = ConvertToMono(Rf) # Convert audio signal Rf, 32 bits, mono
Rf = ConvertAudioTo24bit(Rf) # Resolution Rf 24 bits, mono


# Output audio clip 5.1
#
Sound51 = MergeChannels(Lf, Rf, C, LFE, Ls, Rs) # 5.1 audio clip LPCM, MLP, 24 bits





# In case of standard coefficients of Downmix matrix from the channels Lf, Rf, C, LFE, Ls, Rs received here,
# initial stereo signal shall be recovered with a margin error less than 1%, and
# this 1% percent has nothing in common with non-linear distortions, and
# represents only crosstalk attenuations between channels (in the terms DIN 45500).

.

IanB
6th April 2013, 23:30
The Avisynth audio core works in ieee floating point format, many (most) filters have optional fast 16 bit integer format paths, none have 24bit paths and only one (amplify) have a 32 path. Using ConvertAudioTo24/32bit will mostly result in an automatic ConvertAudioToFloat() being added before each filter. I believe the SoX wrapper layer uses float format exclusively.

ConvertAudioTo24bit() and ConvertAudioTo32bit() are really only useful on the final output from Avisynth to provide the calling application with the format it can best utilise.


Normalising an already normalised clip is a great waste of time. The Normalize() filter reads the entire audio stream on first access to find the peak value. A second instance will still read the entire audio stream a second time to find the same peak as the first time. If you want a -12dB instance of the normalised audio stream, just use AmplifyDB(-12)

IanB
12th April 2013, 00:21
@Jenyok,

Seeing you propagated your script to another thread I thought it might be instructive expose what the audio is actually doing with auto conversion.

All the automatic ConvertAudioToFloat are marked in red :-#
# Algorithm to convert real stereo audio clip to 5.1 audio clip
#
# Input audio clip must be minimum 96 kHz / 24 bits integer real stereo audio clip
#
# All Temporary variables of audio clip in algorithm must be 32 bits integer stereo or mono audio clip
#
# All Output audio clips must be 24 bits integer mono audio clips
#


Input # Input must be stereo audio signal 96 kHz / 24 bits
Tmp = ConvertAudioToFloat(Input)
Input = Normalize(Tmp, 1.0) # Normalize audio signal Input to +0dB


Tmp = ConvertAudioToFloat(Input)
LR = Normalize(Tmp, 0.251) # Normalize audio signal LR to -12dB, stereo
LR = ConvertAudioTo32bit(LR) # Resolution LR 32bits, -12dB, stereo


Tmp = ConvertAudioToFloat(LR)
LRm = FFT_HighPass_Filter(Tmp, 200) # FAST FOURIER TRANSFORM High Pass Filter "/----" 200Hz to LRm, -12dB, stereo
LRm = ConvertAudioTo32bit(LRm) # Resolution LRm 32 bits, -12dB, stereo


# Subwoofer channel
#
Tmp1 = ConvertAudioToFloat(LR)
Tmp2 = ConvertAudioToFloat(LRm)
LFE = MixAudio(Tmp1, Tmp2, 1.0, -1.0) # LFE = LR - LRm, 32 bits, stereo
# or maybe so
#LFE = FFT_LowPass_Filter(LR, 200) # FAST FOURIER TRANSFORM Low Pass Filter "----\" 200Hz to LFE, -12dB, stereo

LFE = ConvertAudioTo32bit(LFE) # Resolution LFE 32 bits, -12dB, stereo
LFE = AmplifyDB(LFE, +9) # Amplify relative audio signal LFE on +9dB (-12dB +9dB), 32 bits, stereo

LFEl = GetChannels(LFE, 1) # Get left audio channel from audio signal LFE, 32 bits, stereo
LFEl = ConvertToMono(LFEl) # Convert audio signal LFEl, 32 bits, mono
LFEr = GetChannels(LFE, 2) # Get right audio channel from audio signal LFE, 32 bits, stereo
LFEr = ConvertToMono(LFEr) # Convert audio signal LFEr, 32 bits, mono

Tmp1 = ConvertAudioToFloat(LFEl)
Tmp2 = ConvertAudioToFloat(LFEr)
LFE = MixAudio(Tmp1, Tmp2, 0.5, 0.5) # LFE = LFEl + LFEr, 32 bits, stereo
LFE = ConvertToMono(LFE) # Convert audio signal LFE, 32 bits, mono
LFE = SHIFTPHASE(LFE, +90, 200) # Shift LFE phase audio signal to +90 grad, frequency 200Hz, 32 bits, mono
LFE = ConvertAudioTo24bit(LFE) # Resolution LFE 24 bits, mono


# Central channel
#
Tmp = ConvertAudioToFloat(LRm)
C = Normalize(Tmp, 0.707) # Normalize audio signal C to -3dB, 32 bits, stereo
C = ConvertAudioTo32bit(C) # Resolution C 32 bits, -3dB, stereo

Cl = GetChhanel(C, 1) # Get left audio channel from audio signal C, 32 bits, stereo
Cl = ConvertToMono(Cl) # Convert audio signal Cl, 32 bits, mono
Cr = GetChhanel(C, 2) # Get right audio channel from audio signal C, 32 bits, stereo
Cr = ConvertToMono(Cr) # Convert audio signal Cr, 32 bits, mono

Tmp1 = ConvertAudioToFloat(Cl)
Tmp2 = ConvertAudioToFloat(Cr)
C = MixAudio(Tmp1, Tmp2, 0.5, 0.5) # C = 0.707 * Cl + 0.707 * Cr, 32 bits, mono
C = ConvertToMono(C) # Convert audio signal C, 32 bits, mono
C = AmplifyDB(C, +3) # Amplify relative audio signal C on +3dB, 32 bits, mono
C = ConvertAudioTo24bit(C) # Resolution C 24 bits, mono


# Front channels preliminary
#
Lc = GetChhanel(LRm, 1) # Get left audio channel from audio signal LRm, -12dB, 32 bits, stereo
Lc = ConvertToMono(Lc) # Convert audio signal Lc, -12dB, 32 bits, mono
Rc = GetChhanel(LRm, 2) # Get right audio channel from audio signal LRm, -12dB, 32 bits, stereo
Rc = ConvertToMono(Rc) # Convert audio signal Rc, -12dB, 32 bits, mono
Tmp1 = ConvertAudioToFloat(Lc)
Tmp2 = ConvertAudioToFloat(Rc)
NLc1 = MixAudio(Tmp1, Tmp2, 0.99, -0.33) # NLc1 = 1.5 * Lc - 0.5 * Rc, 32 bits, mono
Tmp1 = ConvertAudioToFloat(Rc)
Tmp2 = ConvertAudioToFloat(Lc)
NRc1 = MixAudio(Tmp1, Tmp2, 0.99, -0.33) # NRc1 = 1.5 * Rc - 0.5 * Lc, 32 bits, mono
LfRf = MergeChannels(NLc1, NRc1) # Merge channels NLc1, NRc1 to stereo singal LfRf, 32 bits, stereo
LfRf = ConvertAudioTo32bit(LfRf) # Resolution LfRf 32 bits, stereo
LfRf = AmplifyDB(LfRf, +3.61) # Amplify relative audio signal LfRf on +3.61dB, 32 bits, stereo


# Rear channels
#
Tmp = ConvertAudioToFloat(LRm)
LRm_reverb = REVERB(Tmp, "Concert Hall Light") # Reverberation "Concert Hall Light, No combine source Left and Right", 32 bits stereo
LRm_reverb = ConvertAudioTo32bit(LRm_reverb) # Resolution LRm_reverb 32 bits, stereo
Tmp1 = ConvertAudioToFloat(LRm_reverb)
Tmp2 = ConvertAudioToFloat(LRm)
LRm_reverb = MixAudio(Tmp1, Tmp2, 1.0, -1.0) # LRm_reverb = LRm_reverb - LRm, 32 bits, stereo
LRm_reverb = AmplifyDB(LRm_reverb, +6) # Amplify relative audio signal LRm_reverb on +6dB, 32 bits, stereo
Ls = GetChhanel(LRm_reverb, 1) # Get left audio channel from audio signal LRm_reverb, 32 bits, stereo
Ls = ConvertToMono(Ls) # Convert audio signal Ls, 32 bits, mono
Ls = ConvertAudioTo24bit(Ls) # Resolution Ls 24 bits, mono
Rs = GetChhanel(LRm_reverb, 2) # Get right audio channel from audio signal LRm_reverb, 32 bits, stereo
Rs = ConvertToMono(Rs) # Convert audio signal Rs, 32 bits, mono
Rs = ConvertAudioTo24bit(Rs) # Resolution Rs 24 bits, mono


# Front channels
#
Tmp1 = ConvertAudioToFloat(LfRf)
Tmp2 = ConvertAudioToFloat(LRm_reverb)
LfRf = MixAudio(Tmp1, Tmp2, 1.0, -1.0) # LfRf = LfRf - LRm_reverb, 32 bits, stereo
Lf = GetChhanel(LfRf, 1) # Get left audio channel from audio signal LfRf, 32 bits, stereo
Lf = ConvertToMono(Lf) # Convert audio signal Lf, 32 bits, mono
Lf = ConvertAudioTo24bit(Lf) # Resolution Lf 24 bits, mono
Rf = GetChhanel(LfRf, 2) # Get right audio channel from audio signal LfRf, 32 bits, stereo
Rf = ConvertToMono(Rf) # Convert audio signal Rf, 32 bits, mono
Rf = ConvertAudioTo24bit(Rf) # Resolution Rf 24 bits, mono


# Output audio clip 5.1
#
Sound51 = MergeChannels(Lf, Rf, C, LFE, Ls, Rs) # 5.1 audio clip LPCM, MLP, 24 bits



# In case of standard coefficients of Downmix matrix from the channels Lf, Rf, C, LFE, Ls, Rs received here,
# initial stereo signal shall be recovered with a margin error less than 1%, and
# this 1% percent has nothing in common with non-linear distortions, and
# represents only crosstalk attenuations between channels (in the terms DIN 45500).

IanB
12th April 2013, 02:29
As an exercise I removed all the redundant converts and folded the AmplifyDB's into the associated MixAudio's and I optimised all the channel pick and placing to a single channel swap (MergeChannels recognises differing channel counts in the input clips).#
# Algorithm to convert real stereo audio clip to 5.1 audio clip
#
# Input audio clip must be minimum 96 kHz / 24 bits integer real stereo audio clip
#
# All Temporary variables of audio clip in algorithm must be sFloat stereo or mono audio clip
#
# All Output audio clips must be 24 bits integer mono audio clips
#


Input # Input must be stereo audio signal 96 kHz / 24 bits
Input = ConvertAudioToFloat(Input) # Explict conversion to sFloat (would be auto-converted anyway)
LR = Normalize(Input, 0.251) # Normalize audio signal Input once to -12dB

LRm = FFT_HighPass_Filter(LR, 200) # FAST FOURIER TRANSFORM High Pass Filter "/----" 200Hz to LRm, -12dB, stereo


# Subwoofer channel
#
LFE = MixAudio(LR, LRm, 3.0, -3.0) # LFE = LR - LRm, +9db (-12dB +9dB), sFloat, stereo
LFE = ConvertToMono(LFE) # LFE = (0.5*L + 0.5*R), sFloat, mono
LFE = SHIFTPHASE(LFE, +90, 200) # Shift LFE phase audio signal to +90 grad, frequency 200Hz, sFloat, mono


# Central channel
#
C = ConvertToMono(LRm) # C = (0.5*Lm + 0.5*Rm), sFloat, mono


# Rear channels
#
LRm_reverb = REVERB(LRm, "Concert Hall Light") # Reverberation "Concert Hall Light, No combine source Left and Right", sFloat stereo
LrRr = MixAudio(LRm_reverb, LRm, 2.0, -2.0) # LrRr = LRm_reverb - LRm, +6dB, sFloat, stereo


# Front channels
#
RLm = GetChannel(LRm, 2, 1) # Swap audio channel from LRm, -12dB, sFloat, stereo
LfRf = MixAudio(LRm, RLm, 1.5, -0.5) # LfRf = 1.5 * LRm - 0.5 * RLm, sFloat, stereo
LfRf = MixAudio(LfRf, LrRr, 1.0, -1.0) # LfRf = LfRf - LrRr, sFloat, stereo


# Output audio clip 5.1
#
Sound51 = MergeChannels(LfRf, C, LFE, LrRr) # 5.1 audio clip sFloat (2+1+1+2)
Sound51 = ConvertAudioTo24bit(Sound51) # 5.1 audio clip LPCM, MLP, 24 bits
Return Sound51


# In case of standard coefficients of Downmix matrix from the channels Lf, Rf, C, LFE, Ls, Rs received here,
# initial stereo signal shall be recovered with a margin error less than 1%, and
# this 1% percent has nothing in common with non-linear distortions, and
# represents only crosstalk attenuations between channels (in the terms DIN 45500).

Jenyok
12th April 2013, 08:56
IanB
.
I have description with pictures of algorithm to convert stereo to 5.1 audio, but all is in Russian.
If you are interesting.
.

Selur
12th April 2013, 10:52
btw. is there a way to do the stereo to 5.1 conversion with sox (not with Avisynth, using some sox library) without the need for all the temporal files?

IanB
12th April 2013, 23:35
@Jenyok,

Sure, I guess as long as the pictures alone tell enough to work out what is needed.

The 1st scripts I posted was just to illustrate what was happening under the covers with your script. I appreciate 32 bit int can sometimes be better than ieee single precision float with some algorithms, so just in case it was relevant to your approach I posted. The Avisynth audio core mostly offers sFloat and 16 bit int only.

The 2nd post was just an exercise in optimisation. How to express channel peeking and poking without to much actual unpacking and repacking. How to fold amplify into mixaudio. How convert to mono sums all the channels. How to pack channels from various sources. In theory it should work the same as your original script, some of the numbers may be slightly off turning dB back into ratios.

tebasuna51
13th April 2013, 10:42
I want also add my opinion about conversions 2.0 -> 5.1.

First of all, I prefer let original audio untouched and use DSP functions of receivers to do the job at play time.
Recode to 5.1 need more bitrate and can introduce some problems.
BTW, like a exersice, we can do some discussion.

Here you put generic functions like:

FFT_HighPass_Filter(LR, 200)
SHIFTPHASE(LFE, +90, 200)
REVERB(LRm, "Concert Hall Light")

But in this post (http://forum.doom9.org/showthread.php?p=1623486#post1623486) there are SoxFilter/DelayAudio implementations with:

SoxFilter(LR, "highpass 200")
DelayAudio(LFE, Float(phi) / (Float(freq) * 360.0))
SoxFilter(LRm, "reverb 1.0 600.0 240.0 280.0 300.0")

I make some test and:

1) "highpass 200" Butterworth highpass filter
Ther are many low frequencies after it because the cut is not perfect.
Seems the filter intoduce some delay and when use
MixAudio(LR, LRm, 3.0, -3.0)
the LFE channel have many high frequencies and echos.

2) DelayAudio like ShiftPhase work only for one frequency, all others frequencies have different phase shift.
I don't know for what you need the shift. Many subwoofers have a phase adjust to compensate the phisycal location of the speaker.

3) "reverb 1.0 600.0 240.0 280.0 300.0"
Well, can work to obtain the surround channels.
Ther are many options, for that I prefer the DSP functions of the receiver, we can select between several scenarios.

But the main problem for me is the mistake between the LFE channel with the subwoofer speaker.
All audio equipments with a subwoofer attached send the low frequencies from all channels, not only LFE, to the subwoofer speaker by default.
Then, at play time, there are a new filter over all channels, maybe with a different cutoff frequency, than add the outputs over the subwoofer.
This new mix can destroy or enhance frequencies after a inexact soft highpass and phase shift.

For that I recommend do 2.0 -> 5.0 conversions (or 5.1 with LFE empty) and let to the receiver the job of extract low frequencies to the subwoofer.
We can do a highpass for Center (or only vocal band) and Surround channels but not for Front channels

laserfan
13th April 2013, 13:27
I want also add my opinion about conversions 2.0 -> 5.1.

First of all, I prefer let original audio untouched and use DSP functions of receivers to do the job at play time.
I have a receiver that is set to "multi-channel inputs" thus most of the time it just outputs what it is given by the disk player. But then I put-in a movie with 2.0 and of course I get "Stereo" which is a problem in that the "center channel" i.e. dialog is not output from my center channel speaker. Then when I realize this I stop the movie and get-up and change my receiver from "multi-channel IN" to one of the surround modes and I get a much better presentation given my center channel speaker becomes active. Then I have to change the receiver back to "Multi-Channel IN" when that movie is over.

It is interesting to note that I could probably convert the audio for these movies to 3.0 or something but since it's only me and my wife watching 99.9% of the time, and she's used-to my popping-up and changing things occasionally, I agree with your point!

:)

Jenyok
13th April 2013, 18:42
tebasuna51
.
Try to change (to trade) channels, see table, in function MergeChannels(...) in global function StereoTo51(...) .
.
Type Channel1 Channel2 Channel3 Channel4 Channel5 Channel6
---------------------------------------------------------------------------------------------
5.1 WAV Front Left Front Right Central LFE(Subwoofer) Rear Left Rear Right

5.1 AC3 Front Left Central Front Right Rear Left Rear Right LFE(Subwoofer)

5.1 DTS Central Front Left Front Right Rear Left Rear Right LFE(Subwoofer)

5.1 AAC Central Front Left Front Right Rear Left Rear Right LFE(Subwoofer)

5.1 AIFF Front Left Rear Left Central Front Right Rear Right LFE(Subwoofer)
---------------------------------------------------------------------------------------------
.

tebasuna51
13th April 2013, 22:01
Try to change (to trade) channels, see table, in function MergeChannels(...) in global function StereoTo51(...)

For what?
The only valid order inside AviSynth is FL,FR,C,LFE,SL,SR.

IanB
13th April 2013, 23:47
Opps :o Sh0dans Sox plugin is indeed 32 Bit integer. It automatically convert all input formats to 32 bit ints and outputs 32 bit ints.

Jenyok
14th April 2013, 05:15
tebasuna51
.
I tried various variants.
All variants work for AVISynth.
See below.
.

# Sound51 = MergeChannels(Lf, Rf, C, LFE, Ls, Rs) # Sound51 = Merge MONO signals into 5.1 Surround Sound, 5.1 WAV The order Lf Rf C LFE Ls Rs stands for the remapping
Sound51 = MergeChannels(Lf, C, Rf, Ls, Rs, LFE) # Sound51 = Merge MONO signals into 5.1 Surround Sound, 5.1 AC3 The order Lf C Rf Ls Rs LFE stands for the remapping
# Sound51 = MergeChannels(C, Lf, Rf, Ls, Rs, LFE) # Sound51 = Merge MONO signals into 5.1 Surround Sound, 5.1 DTS, 5.1 AAC The order C Lf Rf Ls Rs LFE stands for the remapping
# Sound51 = MergeChannels(Lf, Ls, C, Rf, Rs, LFE) # Sound51 = Merge MONO signals into 5.1 Surround Sound, 5.1 AIFF The order Lf Ls C Rf Rf Rs LFE stands for the remapping

.
.
IanB
.
I know that SoxFilter output is 32 bit integer.
I read documentation to SoxFilter very attentively.
If you would looking for I use ConvertAudioTo16bit() function after all SoxFilter functions.
.

tebasuna51
14th April 2013, 09:40
I tried various variants.
All variants work for AVISynth...

All work but only the first is correct.

If you send the output to a smart encoder, each one do the proper remaping.

odyssey
13th December 2016, 02:09
Excuse me for digging up an old thread.

I'm currently converting a bunch of old tv-show DVD's with only stereo audio. My receiver also defaults to the direct channel input, so since I encode the videos, I thought I could just as well upmix the audio. And that's where I found this thread.

When I let my receiver do the upmixing using DPL2 Movie, it sounds great.

I tried the different profiles here with sox, and all of them (except for the Grezen profile, which seems to just keep the front channels intact), causes the dialogue to almost disappear.

Playing the center channel alone, it sounds like it is isolated correctly, but perhaps need some gain?

Is there a more current method to do this? I tried foobar2000 with foo_fsurround component, which seems to do a nice job as well, but I need something that I can script from commandline on Windows.

Any suggestions?

tebasuna51
13th December 2016, 14:51
Sorry, I only know a correct way to recover the 5.0 from a 2.0 DPL II encoded, and is foo_fsurround.
And I don't know how use Foobar2000 to do that by command line.

Long time ago I used Directshow filters from Cyberlink (maybe with other commercial soft than play DVD's, than need DPL II decoders), but not with recent versions.

odyssey
14th December 2016, 09:07
Sorry, I only know a correct way to recover the 5.0 from a 2.0 DPL II encoded, and is foo_fsurround.
And I don't know how use Foobar2000 to do that by command line.

It certainly also sounds great. I'm going with that approach then, and just splitting my script up :) Thanks!