Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > General > Audio encoding

Reply
 
Thread Tools Search this Thread Display Modes
Old 22nd March 2010, 20:17   #21  |  Link
b66pak
Registered User
 
b66pak's Avatar
 
Join Date: Aug 2008
Location: The Land Of Dracula (Romania - EU)
Posts: 934
thanks...
_
b66pak is offline   Reply With Quote
Old 24th March 2010, 08:44   #22  |  Link
Selur
Registered User
 
Selur's Avatar
 
Join Date: Oct 2001
Location: Germany
Posts: 5,867
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
__________________
Hybrid here in the forum, homepage
Selur is offline   Reply With Quote
Old 24th March 2010, 09:40   #23  |  Link
Selur
Registered User
 
Selur's Avatar
 
Join Date: Oct 2001
Location: Germany
Posts: 5,867
I tried to 'translate' the other profiles too, so here are all the profiles:

Code:
#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
__________________
Hybrid here in the forum, homepage

Last edited by Selur; 24th March 2010 at 09:50.
Selur is offline   Reply With Quote
Old 1st February 2012, 08:05   #24  |  Link
Selur
Registered User
 
Selur's Avatar
 
Join Date: Oct 2001
Location: Germany
Posts: 5,867
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:
Code:
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
__________________
Hybrid here in the forum, homepage

Last edited by Selur; 1st February 2012 at 11:39.
Selur is offline   Reply With Quote
Old 5th April 2013, 07:43   #25  |  Link
moytrage
Registered User
 
Join Date: Mar 2013
Posts: 1
Quote:
Originally Posted by tebasuna51 View Post
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/ta...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:
Code:
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.

Last edited by moytrage; 5th April 2013 at 07:53.
moytrage is offline   Reply With Quote
Old 5th April 2013, 13:44   #26  |  Link
tebasuna51
Moderator
 
tebasuna51's Avatar
 
Join Date: Feb 2005
Location: Spain
Posts: 5,614
Quote:
Originally Posted by moytrage View Post
...
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.
__________________
BeHappy, AviSynth audio transcoder, in Doom9 forums. NicAudio, BassAudio, audio decoders.
tebasuna51 is offline   Reply With Quote
Old 6th April 2013, 06:54   #27  |  Link
Jenyok
Warm and fuzzy
 
Join Date: Apr 2010
Location: Moscow, Russia
Posts: 201
Algorithm to convert real stereo audio clip to 5.1 audio clip.
.
Code:
#
# 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).
.
__________________
Warm and fuzzy (white and fluffy)

Last edited by Jenyok; 6th April 2013 at 09:07.
Jenyok is offline   Reply With Quote
Old 6th April 2013, 23:30   #28  |  Link
IanB
Avisynth Developer
 
Join Date: Jan 2003
Location: Melbourne, Australia
Posts: 3,171
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 is offline   Reply With Quote
Old 12th April 2013, 00:21   #29  |  Link
IanB
Avisynth Developer
 
Join Date: Jan 2003
Location: Melbourne, Australia
Posts: 3,171
@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 :-
Code:
#
# 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 is offline   Reply With Quote
Old 12th April 2013, 02:29   #30  |  Link
IanB
Avisynth Developer
 
Join Date: Jan 2003
Location: Melbourne, Australia
Posts: 3,171
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).
Code:
#
# 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).

Last edited by IanB; 12th April 2013 at 02:34.
IanB is offline   Reply With Quote
Old 12th April 2013, 08:56   #31  |  Link
Jenyok
Warm and fuzzy
 
Join Date: Apr 2010
Location: Moscow, Russia
Posts: 201
IanB
.
I have description with pictures of algorithm to convert stereo to 5.1 audio, but all is in Russian.
If you are interesting.
.
__________________
Warm and fuzzy (white and fluffy)

Last edited by Jenyok; 12th April 2013 at 08:58.
Jenyok is offline   Reply With Quote
Old 12th April 2013, 10:52   #32  |  Link
Selur
Registered User
 
Selur's Avatar
 
Join Date: Oct 2001
Location: Germany
Posts: 5,867
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?
__________________
Hybrid here in the forum, homepage
Selur is offline   Reply With Quote
Old 12th April 2013, 23:35   #33  |  Link
IanB
Avisynth Developer
 
Join Date: Jan 2003
Location: Melbourne, Australia
Posts: 3,171
@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.
IanB is offline   Reply With Quote
Old 13th April 2013, 10:42   #34  |  Link
tebasuna51
Moderator
 
tebasuna51's Avatar
 
Join Date: Feb 2005
Location: Spain
Posts: 5,614
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 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
__________________
BeHappy, AviSynth audio transcoder, in Doom9 forums. NicAudio, BassAudio, audio decoders.
tebasuna51 is offline   Reply With Quote
Old 13th April 2013, 13:27   #35  |  Link
laserfan
Aging Video Hobbyist
 
Join Date: Dec 2004
Location: Off the Map
Posts: 2,457
Quote:
Originally Posted by tebasuna51 View Post
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!

laserfan is offline   Reply With Quote
Old 13th April 2013, 18:42   #36  |  Link
Jenyok
Warm and fuzzy
 
Join Date: Apr 2010
Location: Moscow, Russia
Posts: 201
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)
---------------------------------------------------------------------------------------------
.
__________________
Warm and fuzzy (white and fluffy)

Last edited by Jenyok; 13th April 2013 at 18:49.
Jenyok is offline   Reply With Quote
Old 13th April 2013, 22:01   #37  |  Link
tebasuna51
Moderator
 
tebasuna51's Avatar
 
Join Date: Feb 2005
Location: Spain
Posts: 5,614
Quote:
Originally Posted by Jenyok View Post
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.
__________________
BeHappy, AviSynth audio transcoder, in Doom9 forums. NicAudio, BassAudio, audio decoders.
tebasuna51 is offline   Reply With Quote
Old 13th April 2013, 23:47   #38  |  Link
IanB
Avisynth Developer
 
Join Date: Jan 2003
Location: Melbourne, Australia
Posts: 3,171
Opps Sh0dans Sox plugin is indeed 32 Bit integer. It automatically convert all input formats to 32 bit ints and outputs 32 bit ints.
IanB is offline   Reply With Quote
Old 14th April 2013, 05:15   #39  |  Link
Jenyok
Warm and fuzzy
 
Join Date: Apr 2010
Location: Moscow, Russia
Posts: 201
tebasuna51
.
I tried various variants.
All variants work for AVISynth.
See below.
.
Code:
#  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.
.
__________________
Warm and fuzzy (white and fluffy)

Last edited by Jenyok; 14th April 2013 at 05:26.
Jenyok is offline   Reply With Quote
Old 14th April 2013, 09:40   #40  |  Link
tebasuna51
Moderator
 
tebasuna51's Avatar
 
Join Date: Feb 2005
Location: Spain
Posts: 5,614
Quote:
Originally Posted by Jenyok View Post
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.
__________________
BeHappy, AviSynth audio transcoder, in Doom9 forums. NicAudio, BassAudio, audio decoders.
tebasuna51 is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 23:56.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2019, vBulletin Solutions Inc.