Log in

View Full Version : Sox Audio Effect Filters v1.1 beta


Pages : [1] 2

sh0dan
29th December 2005, 16:43
This christmas holiday brought a new filter to extend sound processing support in AviSynth.

This plugin will allow you to run SOX effects within AviSynth. Most effects are supported, and multiple effects can be stacked after eachother.

You can download it here: http://forum.doom9.org/showthread.php?p=761154#post761154

Usage
SoxFilter(clip, string effect1 [, string effect 2, string effect 3...])

Any number of effects can be entered, and they will be executed in the order they are specified. Effect syntax is just like SOX. See Effect Overview and Filter Reference below.

A simple filter could look like this:
AviSource("movie.avi")
SoxFilter("bandpass 500 100")
convertAudioTo16Bit()
This will keep a 100Hz band around 500Hz. SoxFilter converts audio to 32 bit integers. This allows to keep the additional dynamic range of float point samples, but it requires a convertion to 16 bit audio before output, since most codecs only support 16 bit.

Multiple effects can be stacked like this:
AviSource("movie.avi")
SoxFilter("bandpass 2000 1000", "vol 2.0", "reverb 1.0 600.0 180.0 200.0 220.0 240.0")
ConvertAudioTo16Bit()

Known Issues
* Linear access is heavily recommended. SOX filters doesn't support seeking, so stream is restarted every time a samples previous to the last one is requested.
* The AviSynth version is VERY picky about spaces. If you make double spaces or a space before or after the quotes the command will not be recognized.
* If one filter doesn't support multichannel audio the entire chain is converted to mono filters, this might affect some filters like "earwax". Use multiple filter instaces instead.
* Some filters have been removed since they were incompatible with the AviSynth version. All these filters have internal Avisynth equivalents.
* compand is very unstable in the current interface, and doesn't support restarts (distorted audio). Don't use this together with other effetcs.
* The length of audio cannot be modified.

Feedback and bugs here, but please check if it is not a SOX problem, if possible.

dimzon
29th December 2005, 16:49
WOW! Thanx a lot!

sh0dan
29th December 2005, 17:07
Just realised I'd left out some options in the docs of the newest version. I'll add them now.

Edit: Page and archives updated.

FredThompson
2nd January 2006, 01:10
Host server is dead, Apache 409 error...

FredThompson
2nd January 2006, 16:31
Ah, noise removal looks promising for simple things like system hum.

sh0dan
3rd January 2006, 00:02
v 1.1:

* Solved issue with earwax refusing to play.
* Solved problem with time alternating effects.
* Solved issues with some filters producing clicks.
* Made sure compand and mcompand doesn't crash. Still quite buggy though.

Attached. Please test, and report your findings here!

Mug Funky
3rd January 2006, 03:08
that's awesome! thanks a lot!

i'll have to play around with this a tad now. the noise reduction looks interesting, as does the compander/ multiband companding (is there a peak limit as well?).

looks like i might be able to speed up some of my audio stuff now :)

btw, happy new year

Mug Funky
3rd January 2006, 15:05
excellent :)

it seems its frequency filters are perfectly reconstructible. i would expect it that way anyway, but it's good to know.

try this line - it cuts a source into 3 bands, then mixes them back together, then subtracts that from the source. the point being that if you hear anything at all, the filters are not PR.

mixaudio(last,\
mixaudio(last.soxfilter("filter 3000-6000 128"),\
mixaudio(last.soxfilter("filter 0-3000 128"),last.soxfilter("filter 6000-24000 128"),1,1)\
,1,1)\
,1,-1)

though it seems to take a bit of playback for it to go silent... they start out of sync, then each band gets back in sync 1 by 1 in the space of a few seconds.

[edit] disregard that. it's because i couldn't find a decent source on my home machine.... ensureVBRmp3sync fixed it. all is right with the world.

[edit 2]

i'm playing with this a fair bit (as you can no doubt tell), and have noticed that mixaudio seems to be returning 16-bit even though it's fed with float audio. is something amiss?

i'm doing my own multiband compression (sox's one seems to only support 2 bands, which is enough for speech but not music if you really want to smash it but avoid pumping) and i need mixaudio at the end to put the bands back together again. i'm getting clipping in the bass and 16-bit audio output though :(

here's my script:

avisource("blah.avi").ensurevbrmp3sync()
audiodub(last,wavsource("Led Zeppelin - II.wav"))

convertaudiotofloat()
c=last

band1 = c.soxfilter("filter 0-250 192","compand .05,1. -30,-30,-0,-27.3")
band2 = c.soxfilter("filter 250-2500 192","compand .01,.5 -34.3,-34.3,-0,-31.3")
band3 = c.soxfilter("filter 2500-12000 192","compand .01,.5 -38.3,-38.3,-0,-34.8")
band4 = c.soxfilter("filter 12000-24000 192","compand .01,.5 -34.9,-34.9,-0,-31.8")
band2
mixaudio(mixaudio(band1,band2,1,1),mixaudio(band3,band4,1,1),1,1)


hehe... it took me a while to realise i couldn't do a 0-250Hz band with an fft size of 128... though i'm not sure if power-of-2 fft sizes are faster or not.

just in case you're interested, the numbers in the compander are exported from audition, and based on -20dB pink noise with 8:1 compression above -20dB (numbers are different due to each band having different power... i wish i had the maths to do this analytically). the idea behind it is no matter how much you amplify the input (assuming float values that don't have a problem with positive dB), it will always give you a nice eq curve. works okay in audition, but it's hellishly slow and requires intermediate files.

sh0dan
3rd January 2006, 21:22
i'm playing with this a fair bit (as you can no doubt tell), and have noticed that mixaudio seems to be returning 16-bit even though it's fed with float audio. is something amiss?
If the sample type is float, when AviSynth has to output the data, it will be converted to 16 bit, since float cannot be passed as valid AVI data.

Mug Funky
4th January 2006, 03:36
hmm. i could have sworn i was seeing 32 bit audio when not using mixaudio...? i'm trying it here at work and it appears you're right about it returning 16 bit. is it possible my (newer) version of virtualdub at home is actually accepting 32 bits? or is it more likely i was looking at it wrong :)

btw, is it possible to get 32 bit audio out using avs2wav?

sorry to bug you with these questions. i'm quite eager to replace a 2 hour cool edit operation with a 5 min avs one :). i'm already getting nice results, but perhaps i should ease back on the loudness and the clipping will go away (i'm still not sure it isn't coming from mixaudio... how does that deal with beyond fullscale stuff in float?)

TheBashar
5th March 2007, 10:40
Please test, and report your findings here!

I've been trying to use the compander filter via this sox plugin to do some DRC on some videos I'm splicing together with Aligned Splices. I have to that make avisynth / sox / compander lock up with ++ but not with +. Do you have any suggestions how I might accomplish the aligned splice without causing compander to go off in the weeds?

Thanks!

More Info:

Okay, it looks like the pure silence that AlignedSplice adds is sending the compander off to never-never land. Here is an example of what bombs when encoding in MeGUI and how to hack around it:


clipA = DirectShowSource("clipA.avi").ConvertToMono().SoxFilter("compand 0.1,0.3 -90,-90,-70,-55,-50,-35,-31,-31,-21,-21,0,-20 0 0 0.1")
# NOTE: clipA audio duration < clipA video duration
clipB = DirectShowSource("clipB.avi").ConvertToMono().SoxFilter("compand 0.1,0.3 -90,-90,-70,-55,-50,-35,-31,-31,-21,-21,0,-20 0 0 0.1")

blank = BlankClip(A)
tonal = Tone(blank.AudiolengthF/blank.Audiorate, 440, clipA.Audiorate, 1, "silence", 0.0)

works1 = clipA + clipB
hangs1 = clipA ++ clipB

hangs2 = AudioDubEx(clipA, MixAudio(blank, clipA, 0.0, 1.0)) + clipB
works2 = AudioDubEx(clipA, MixAudio(tonal, clipA, 0.0, 1.0)) + clipB


What befuddles me so much is how can mixing in the silent audio from the BlankClip cause a hang, but mixing in the silence from a Tone(type="silence", level=0.0) with a 0.0 clip_factor in MixAudio not cause the hang??

Solution:

It seems that the last parameter in the "compand" function is what is causing the problem. I copied this black magic from this post: http://forum.doom9.org/showpost.php?p=779165&postcount=60 As it turns out, even after my ++ replacement hackery, it was still crashing on other samples. Increasing that last parameter from 0.1 to 0.2 made the filter able to accept more and more of my test samples. So far, at 0.2, I am not getting any hangs.

nikio
25th April 2009, 11:03
Hello everyone,
I'm not very familiar with this, I need to upmix an audio trace and my behappy seems to need this SoxFilter.dll. After a long serch I found the 1.1 version dated 2006, is this the newest version?

tebasuna51
26th April 2009, 00:04
Yes, this is the newest I know.

At least this is the last tested with BeHappy.

royia
4th September 2010, 09:07
Is there a better Audio Noise Reduction plug ins for AVI Synth or this is as good as it gets?

Thanks.

Jenyok
14th December 2011, 05:14
sh0dan

Need following.
.
I have two video clip with sound track in each.
Parameters of sound tracks in different video clips are equal.
I need following with sound tracks in video clips, like as video contetnt,
Sound1 - Sound2 (mines) or similar to function Subtract() in video content, but for sound tracks...

Sound1=A1 * Sin(2 * PI * f1 * t1 + fi1)
Sound2=A2 * Sin(2 * PI * f2 * t2 + fi2)
where
A1, A2 - amplitude of sound wave
f1, f2 - frequency of sound wave
t1, t2 - time, in our case are equal t1 = t2 = t
fi1, fi2 - phase of sound wave
PI = 3.1415926

Sound = Sound1 - Sound2 = A1 * Sin(2 * PI * f1 * t + fi1) - A2 * Sin(2 * PI * f2 * t + fi2)
for each time counting

How can I do this ?

Maybe update SoxFilter() for subtraction audio tracks in clips, for (as) example,

SoxFilter(clip1, clip2, string "subtract")
and return result subtraction clip (audio subtraction), if (clip2 != NULL) ...
And so on...

Gavino
14th December 2011, 12:18
Tone (http://avisynth.org/mediawiki/Tone) will generate a sine wave of a given frequency.
You can't set the phase, although I suppose you could use Trim() to achieve that.

To subtract the audio of two clips, use
MixAudio (http://avisynth.org/mediawiki/MixAudio)(clip1, clip2, 1.0, -1.0)

Jenyok
14th December 2011, 16:57
This is a simple Pseudo Stereo Algorythm for mono audio track.
Based on physic's laws.
For you usage...
It works fine (for me)...
.

#
# Pseudo Stereo algorythm
# Based on physic's laws
#

audio = BassAudioSource("...your sound file...")

audio = GetChannel(audio, 1) # Get MONO signal Left channel -> Получаем левый канал, звук "МОНО"
audio = ConvertToMono(audio)
left_channel = audio
right_channel = DelayAudio(audio, 0.0121) # t=0.0121 sec (v=331 m/sec) ~4 m between sound source L and R in room -> 0.0121 сек (331 м/сек) ~ 4 м между источниками звука L и R
left_channel = Normalize(left_channel, 0.99)
right_channel = Normalize(right_channel, 0.99)
left_channel_delay = DelayAudio(left_channel, 0.000755) # t=0.000775 sec (v=331 m/sec) ~0.25 m between ears -> 0.000755 сек (331 м/сек) ~ 0.25 м (25 см) среднее расстояние между "ушами"
right_channel_delay = DelayAudio(right_channel, -0.000755) # t=0.000775 sec (v=331 m/sec) ~0.25 m between ears -> 0.000755 сек (331 м/сек) ~ 0.25 м (25 см) среднее расстояние между "ушами"
left_channel = MixAudio(left_channel, right_channel_delay, 0.6, 0.4)
right_channel = MixAudio(right_channel, left_channel_delay, 0.6, 0.4)
left_channel = Normalize(left_channel, 0.99)
right_channel = Normalize(right_channel, 0.99)
stereo = MergeChannels(left_channel, right_channel)
stereo = Normalize(stereo, 0.99)

.
This is a New Pseudo Stereo Algorythm for mono audio track.
Algorythm is described in Russian magazine "Radio" №7 1982 year.
For you usage...
It works fine (for me)...
.

#
# New pseudo Stereo algorythm
# Radio Magazine 07-1982, page 47-50
#
#
# Plugins:
#
# SoxFilter()
#



LoadPlugin("C:\PROGRAM FILES\AVISYNTH 2.5\PLUGINS\SOXFILTER_11\soxfilter.dll")



# Constants
#
K2 = 0.5 # K2 = [0.00 .. 1.00]
FNCH = 300.00 # Low Pass Filter (ФНЧ) = [150 .. 500] Hz (Гц)
SLevel = 1.00 # Sound Volume Level (Уровень звука) = [0.75 .. 1.00]

# Constants
# ! Do not change this constants !
#
Kf1 = 0.17 # ! Do not change this constant !
Kf2 = 0.83 # ! Do not change this constant !
Kf3 = 1.83 # ! Do not change this constant !
Kf4 = 2.00 # ! Do not change this constant !
KLevel = 0.85 # ! Do not change this constant ! # Требует небольшой подстройки под конктретный звук
SQRT2 = 1.414 # Square root 2 (Корень из 2)

# Constants
#
LChannel = 1 # Get Left Channel (Левый канал)
LowPass = "lowpass " # Low Pass Filter (ФНЧ)
HighPass = "highpass " # High Pass Filter (ФВЧ)
VLevel = "vol " # Volume Level normalization

# Constants
#
SLevel2 = 2.00 # Sound Volume Level (Уровень звука) = [1.00 .. 3.00] # First Sound Volume Level normalization
SLevel3 = 10.0 # Final Sound Volume Level normalization


# Variables
#
# RightChannel
# LeftChannel
# LeftChannel2 # Mono signal (Моно сигнал), work variable...
# Afnch
# Bfvch
# Stereo
#
# EqC1 # Variable
# EqC2 # Variable
# EqC3 # Variable
# EqC4 # Variable
#
# EqZL # Variable
# EqZR # Variable



K2 = (K2 < 0.00) ? 0.00 : (K2 > 1.00) ? 1.00 : K2
FNCH = (FNCH < 150.00) ? 150.00 : (FNCH > 500.00) ? 500.00 : FNCH
SLevel = (SLevel < 0.75) ? 0.75 : (SLevel > 1.00) ? 1.00 : SLevel
SLevel2 = (SLevel2 < 1.00) ? 1.00 : (SLevel2 > 3.00) ? 3.00 : SLevel2



BlankClip(length=72250, width=768, height=576, audio_rate=44100, fps=25.0) # Only for test

Left=WAVSource("C:\Z_DISK_C\PICTURE\JENYOK\SCHOOL_47_KURGAN\VIDEO\DVD 25YEARS DISK6 ФИЛЬМ УЧИТЕЛЬ V1_00 (OLD, +AVI, +AVS)\ZAVS\teacher t01 2_0ch 256kbps 44.1khz.wav")


LeftChannel2 = Left.KillVideo() # Get Audio Channel, kill Video content
#LeftChannel2 = GetChannel(LeftChannel2, LChannel).KillVideo() # Get Audio Channel, kill Video content
LeftChannel2 = ConvertToMono(LeftChannel2)
LeftChannel2 = SoxFilter(LeftChannel2, VLevel+String(SLevel2)) # Normalize sound Volume Level = SLevel2


#
# Afnch = LowPass_Filter(LeftChannel2, FNCH)
#
#
# Bfvch = LeftChannel2 - Afnch
#
# Bfvch = HighPass_Filter(Bfvch, FNCH)
#
#
# LeftChannel = SQRT(2) * (Afnch - 2 * K2 * Afnch + 1.83 * K2 * LeftChannel2 - 0.83 * K2 * K2 * LeftChannel2)
#
# RightChannel = SQRT(2) * (Bfvch + 2 * K2 * Afnch - 0.17 * K2 * LeftChannel2 - 0.83 * K2 * K2 * LeftChannel2)
#


Afnch = SoxFilter(LeftChannel2, LowPass+String(FNCH)) # 300 Hz (Гц) Low Pass Filter (ФНЧ 300 Гц)
Afnch = SoxFilter(Afnch, VLevel+String(SLevel)) # Normalize sound Volume Level = SLevel

Bfvch = MixAudio(LeftChannel2, Afnch, 1.0, -1.0) #
Bfvch = SoxFilter(Bfvch, VLevel+String(SLevel*KLevel)) # Normalize sound Volume Level = SLevel*KLevel
Bfvch = SoxFilter(Bfvch, HighPass+String(FNCH)) # 300 Hz (Гц) High Pass Filter (ФВЧ 300 Гц)
Bfvch = SoxFilter(Bfvch, VLevel+String(SLevel)) # Normalize sound Volume Level = SLevel

EqC1 = SoxFilter(Afnch, VLevel+String(Kf4 * K2))
EqC2 = SoxFilter(LeftChannel2, VLevel+String(Kf3 * K2))
EqC3 = SoxFilter(LeftChannel2, VLevel+String(Kf2 * K2 * K2))
EqC4 = SoxFilter(LeftChannel2, VLevel+String(Kf1 * K2))


EqZL = MixAudio(Afnch, EqC1, 1.0, -1.0)
EqZL = SoxFilter(EqZL, VLevel+String(SLevel)) # Normalize sound Volume Level = SLevel
EqZL = MixAudio(EqZL, EqC2, 0.5, 0.5)
EqZL = SoxFilter(EqZL, VLevel+String(SLevel)) # Normalize sound Volume Level = SLevel
EqZL = MixAudio(EqZL, EqC3, 1.0, -1.0)
EqZL = SoxFilter(EqZL, VLevel+String(SLevel)) # Normalize sound Volume Level = SLevel

EqZR = MixAudio(Bfvch, EqC1, 0.5, 0.5)
EqZR = SoxFilter(EqZR, VLevel+String(SLevel)) # Normalize sound Volume Level = SLevel
EqZR = MixAudio(EqZR, EqC4, 1.0, -1.0)
EqZR = SoxFilter(EqZR, VLevel+String(SLevel)) # Normalize sound Volume Level = SLevel
EqZR = MixAudio(EqZR, EqC3, 1.0, -1.0)
EqZR = SoxFilter(EqZR, VLevel+String(SLevel)) # Normalize sound Volume Level = SLevel


LeftChannel = SoxFilter(EqZL, VLevel+String(SQRT2))
RightChannel = SoxFilter(EqZR, VLevel+String(SQRT2))


Stereo = MergeChannels(LeftChannel, RightChannel)
Stereo = SoxFilter(Stereo, VLevel+String(SLevel3)) # Normalize sound Volume Level = SLevel3
Stereo = ConvertAudioTo16bit(Stereo)

AudioDub(last, Stereo)

ConvertToYUY2()

markanini
16th December 2011, 09:42
What happens when the audio is mixed back down to mono?

Jenyok
8th January 2012, 12:35
This is a 5.1 Audio Algorythm for stereo audio track.
Algorythm is described in internet.
For you usage...
It works fine (for me)...
Only it is needed more better reverberation effect from SoxFolter() function, such as for example, "Adobe Audition CS5.5 -> Effects -> Reverb -> Big Drum Room" ...
Reverberation effect in SoxFilter() function is very slow.


#
# 5.1 Audio Algorythm for stereo audio track
#
#
# Plugins:
#
# SoxFilter()
#


LoadPlugin("C:\PROGRAM FILES\AVISYNTH 2.5\PLUGINS\SOXFILTER_11\soxfilter.dll")

function StereoTo51(clip clp)
{
# Output
#
# 5.1 sound 24 bits

# Constants
#
# WAV 2.0 stereo
# 1 - Left channel
# 2 - Right channel
#
# WAV 5.1 channels
# 1 - Lf Front Left channel
# 2 - Rf Front Right channel
# 3 - C Front Central channel
# 4 - LFE Subwoofer
# 5 - Ls Rear Left channel
# 6 - Rs Rear Right channel
#
LChannel = 1 # Set default Left Channel (Левый канал)
RChannel = 2 # Set default Right Channel (Правый канал)

VLevel0 = "vol 0.0 dB" # Volume Level normalization to 0.0 dB
VLevel03 = "vol 3.0 dB" # Volume Level normalization to 3.0 dB
VLevel361 = "vol 3.61 dB" # Volume Level normalization to 3.61 dB
VLevel6 = "vol 6.0 dB" # Volume Level normalization to 6.0 dB
VLevel9 = "vol 9.0 dB" # Volume Level normalization to 9.0 dB
VLevel3 = "vol -3.0 dB" # Volume Level normalization to -3.0 dB
VLevel12 = "vol -12.0 dB" # Volume Level normalization to -12.0 dB

HPass = "highpass 200.0" # HighPass Filter 200 Hz "/---"
LPass = "lowpass 200.0" # LowPass Filter 200 Hz "---\"

Reverb = "reverb 0.4 700 262 350 175" # reverbe time 700 -> delay time [350 .. 175]



Stereo = KillVideo(clp) # Get Audio Channels, kill Video content
Stereo = GetChannels(Stereo, LChannel, RChannel) # Get Left and Right Audio Channels (stereo)

# Convert audio stereo signal to 32 bits (SoxFilter() function)
# Normalize to 0.0 dB
#
Stereo = SoxFilter(Stereo, VLevel0) # Normilize audio Stereo to 0.0 dB

# Work audio stereo signal
# Normalize to -12.0 dB
#
LR = SoxFilter(Stereo, VLevel12) # Normilize audio LR to -12.0 dB

# Work audio stereo signal2
# LRm = HighPass_Filter(LR, 200)
#
LRm = SoxFilter(LR, HPass) # HighPass Filter 200 Hz LRm "/---"

# LFE = LR - LRm
# LFE = LowPass_Filter(LFE, 200)
#
LFE = MixAudio(LR, LRm, 1.0, -1.0) # LFE = LR - LRm
LFE = SoxFilter(LFE, LPass) # LowPass Filter 200 Hz LFE "---\"
LFE = SoxFilter(LFE, VLevel9) # Normilize audio LFE to 9.0 dB
LFEl = GetChannel(LFE, LChannel) # LFEl = Left_channel(LFE)
LFEl = ConvertToMono(LFEl)
LFEr = GetChannel(LFE, RChannel) # LFEr = Right_channel(LFE)
LFEr = ConvertToMono(LFEr)
LFE = MixAudio(LFEl, LFEr, 0.5, 0.5) # LFE = LFEl + LFEr
LFE = ConvertToMono(LFE)
LFE = ConvertAudioTo24bit(LFE) # LFE (Subwoofer) audio mono signal 24 bits

#
#
C = SoxFilter(LRm, VLevel3) # Normilize audio C to -3.0 dB
Cl = GetChannel(C, LChannel) # Cl = Left_channel(C)
Cl = ConvertToMono(Cl)
Cr = GetChannel(C, RChannel) # Cr = Right_channel(C)
Cr = ConvertToMono(Cr)
C = MixAudio(Cl, Cr, 0.5, 0.5) # C = 0.707 * Cl + 0.707 * Cr
C = SoxFilter(C, VLevel03) # Normilize audio C to 3.0 dB
C = ConvertToMono(C)
C = ConvertAudioTo24bit(C) # C central audio mono signal 24 bits

#
#
Lc1 = GetChannel(LRm, LChannel) # Lc1 = Left_channel(LRm)
Lc1 = ConvertToMono(Lc1)
Rc1 = GetChannel(LRm, RChannel) # Rc1 = Right_channel(LRm)
Rc1 = ConvertToMono(Rc1)
NLc1 = MixAudio(Lc1, Rc1, 0.99, -0.33) # Lc = 0.99 * Lc - 0.33 * Rc
NRc1 = MixAudio(Rc1, Lc1, 0.99, -0.33) # Rc = 0.99 * Rc - 0.33 * Lc
LfRf = MergeChannels(NLc1, NRc1) # Merge channels to stereo singal LfRf
LfRf = SoxFilter(LfRf, VLevel361) # Normilize audio LfRf to 3.61 dB, 32 bits

#
#
LRm_reverb = SoxFilter(LRm, Reverb) # LRm_reverb = Reverberation(LRm)
LRm_reverb = MixAudio(LRm_reverb, LRm, 1.0, -1.0) # LRm_reverb = LRm_reverb - LRm
LRm_reverb = SoxFilter(LRm_reverb, VLevel6) # Normilize audio LRm_reverb to 6.0 dB
Ls = GetChannel(LRm_reverb, LChannel) # Ls = Left_channel(LRm_reverb)
Ls = ConvertToMono(Ls)
Ls = ConvertAudioTo24bit(Ls) # Ls rear left channel mono signal 24 bits
Rs = GetChannel(LRm_reverb, RChannel) # Rs = Right_channel(LRm_reverb)
Rs = ConvertToMono(Rs)
Rs = ConvertAudioTo24bit(Rs) # Rs rear right channel mono signal 24 bits

#
#
LfRf = MixAudio(LfRf, LRm_reverb, 1.0, -1.0) # LfRf = LfRf - LRm_reverb
Lf = GetChannel(LfRf, LChannel) # Lf = Left_channel(LfRf)
Lf = ConvertToMono(Lf)
Lf = ConvertAudioTo24bit(Lf) # Lf front left channel mono signal 24 bits
Rf = GetChannel(LfRf, RChannel) # Rf = Right_channel(LfRf)
Rf = ConvertToMono(Rf)
Rf = ConvertAudioTo24bit(Rf) # Rf front right channel mono signal 24 bits

Lf = SoxFilter(Lf, VLevel0)
Rf = SoxFilter(Rf, VLevel0)
C = SoxFilter(C, VLevel0)
LFE = SoxFilter(LFE, VLevel0)
Ls = SoxFilter(Ls, VLevel0)
Rs = SoxFilter(Rs, VLevel0)
Sound51 = MergeChannels(Lf, Rf, C, LFE, Ls, Rs)
Sound51 = ConvertAudioTo24bit(Sound51)

return (Sound51)

# Only for debugging
# return (ConvertAudioTo16bit(MergeChannels(Lf, Rf, C, LFE, Ls, Rs)))
# return (ConvertAudioTo16bit(Stereo))
# return (ConvertAudioTo16bit(LR))
# return (ConvertAudioTo16bit(LRm))
# return (ConvertAudioTo16bit(LFE))
# return (ConvertAudioTo16bit(C))
# return (ConvertAudioTo16bit(LfRf))
# return (ConvertAudioTo16bit(LRm_reverb))
}

.
sh0dan
If you are not hard,
please,
see "Adobe Audition CS5.5 -> Effects -> Reverb -> Big Drum Room" function
and try to do SoxFilter() as copy of this Adobe function...
Very very need it !!!
5.1 Audio Algorythm will work more good, more better...
.
Thanks a lot...

Jenyok
11th January 2012, 10:10
sh0dan

Are you here ?

Jenyok
30th January 2012, 19:18
New algorithm.
Convert MONO signal (1 channel) into PSEUDO STEREO signals (2 channels).


#
# New Stereo algorythm for MONO audio track
#
# Plugins:
# SoxFilter()
#
function PseudoStereo3(clip clp, float "SLevel", float "SLevel2", int "Channel")
{
# Default variables
#
Channel = Default(Channel, 1) # Set default Left Channel (Левый канал)
SLevel = Default(SLevel, 1.00) # Work Sound Volume Level (Уровень звука) = [0.75 ... 1.00] normalization
SLevel2 = Default(SLevel2, 1.00) # Output Sound Volume Level (Уровень звука) = [0.75 ... 1.00] normalization

# Constants
#
Delay1 = 0.012000 # t=0.0120 sec (v=331 m/sec) ~4 m between sound source L and R in room
# 0.0120 сек (331 м/сек) ~ 4 м между источниками звука L и R

# Constants
#
F1 = 200
F2 = 2000
dF = 50

# Constants
#
LowPass = "lowpass " # Low Pass Filter (ФНЧ)
HighPass = "highpass " # High Pass Filter (ФВЧ)
VLevel = "vol " # Volume Level normalization

# Variables
#
# LeftChannel
# RightChannel
# Stereo
# LeftChannel2 = Input sound
# Left1
# Left2
# Left3

SLevel = (SLevel < 0.75) ? 0.75 : (SLevel > 1.00) ? 1.00 : SLevel
SLevel2 = (SLevel2 < 0.75) ? 0.75 : (SLevel2 > 1.00) ? 1.00 : SLevel2

LeftChannel2 = KillVideo(clp) # Get Audio Channel(s), kill Video content
LeftChannel2 = GetChannel(LeftChannel2, Channel) # Get Left (Right) Audio Channel
LeftChannel2 = ConvertToMono(LeftChannel2)
LeftChannel2 = SoxFilter(LeftChannel2, VLevel+String(SLevel)) # Normalize First Sound Volume Level = SLevel

Left1 = LeftChannel2
Left2 = LeftChannel2
Left3 = LeftChannel2

Left1 = SoxFilter(Left1, LowPass+String(F1 - dF)) # 150 Hz (Гц) Low Pass Filter (ФНЧ 150 Гц)
Left1 = SoxFilter(Left1, VLevel+String(SLevel)) # Normalize First Sound Volume Level = SLevel

Left2 = SoxFilter(Left2, HighPass+String(F1 + dF)) # 250 Hz (Гц) High Pass Filter (ФВЧ 250 Гц)
Left2 = SoxFilter(Left2, VLevel+String(SLevel)) # Normalize First Sound Volume Level = SLevel
Left2 = SoxFilter(Left2, LowPass+String(F2 - dF)) # 1950 Hz (Гц) Low Pass Filter (ФНЧ 1950 Гц)
Left2 = SoxFilter(Left2, VLevel+String(SLevel)) # Normalize First Sound Volume Level = SLevel

Left3 = SoxFilter(Left3, HighPass+String(F2 + dF)) # 2050 Hz (Гц) High Pass Filter (ФВЧ 2050 Гц)
Left3 = SoxFilter(Left3, VLevel+String(SLevel)) # Normalize First Sound Volume Level = SLevel

LeftChannel = MixAudio(Left1, Left2, 0.5, 0.5)
LeftChannel = SoxFilter(LeftChannel, VLevel+String(SLevel)) # Normalize First Sound Volume Level = SLevel
LeftChannel = MixAudio(LeftChannel, Left3, 0.5, 0.5)
LeftChannel = SoxFilter(LeftChannel, VLevel+String(SLevel)) # Normalize First Sound Volume Level = SLevel
LeftChannel = AmplifydB(LeftChannel, 8) # Amplify volume of LeftChannel to 8 dB. Need to tune.

RightChannel = MixAudio(LeftChannel, LeftChannel2, 1.0, -1.0)
RightChannel = DelayAudio(RightChannel, Delay1)
RightChannel = SoxFilter(RightChannel, VLevel+String(SLevel)) # Normalize First Sound Volume Level = SLevel

Stereo = MergeChannels(LeftChannel, RightChannel)
Stereo = SoxFilter(Stereo, VLevel+String(SLevel2)) # Normalize First Sound Volume Level = SLevel2
Stereo = ConvertAudioTo16Bit(Stereo)

return (Stereo)
}


sh0dan

Are you here, mate ?

Jenyok
30th March 2013, 09:39
There are some functions to convert MONO audio signal to PSEUDO STEREO.
There is a function to convert stereo audio signal to 5.1 audio signal.
.
See description in code section.
See attached RAR file.
.
.

#
#
# File: Stereo.avsi
#
#
# Date: 30.03.2013 year
# Version: 1.3
#
#
# License: GNU GENERAL PUBLIC LICENSE
#
#
# Author: Jenyok (Evgeniy Gurovskikh, Russia, Moscow)
# E-Mail: e_gurovskikh@mail.ru
#
#
#
# Functions (pseudo Stereo and other sound functions) for AVISynth
#
# For all occasions of life (На все случаи жизни) ...
#
#
#
# Plugin and Import
#
# SoxFilter.dll
#
#
#
# function PhaseShift(clip clp, float "freq", float "phi", int "Channel") Shift (rotate) phase of audio to a different angle (corner)
#
# function PseudoStereo3(clip clp, int "Channel", bool "isDelay") Described: Magazine "Radio" № 6, 1985 year, page 62 (USSR, Russia)
# function PseudoStereo33(clip clp, int "Channel", bool "isDelay") Described: Magazine "Radio" № 6, 1985 year, page 62 (USSR, Russia)
#
# function PseudoStereo4(clip clp, int "Channel", bool "isDelay") US Patent No 6,636,608 B1
# function PseudoStereo43(clip clp, int "Channel", bool "isDelay") US Patent No 6,636,608 B1
#
# function PseudoStereo5(clip clp, int "Channel", bool "isDelay") Analog: Philips chip TDA3810 (sound porcessor)
# function PseudoStereo52(clip clp, int "Channel", bool "isDelay") Analog: Philips chip TDA3810 (sound porcessor)
#
# function StereoEnhancer(clip clp) Analog: Philips chip TDA3810 (sound porcessor)
#
#
# function StereoTo51(clip clp, bool "is24bit") Build 5.1 Sound Audio track from stereo signal,
# 24 bits output (24 bits is a standard ?)
#
#
# function Dmix3Stereo(clip a) Downmix sound functions
# function Dmix3Dpl(clip a) Downmix sound functions
# function Dmix4lStereo(clip a) Downmix sound functions
# function Dmix4qStereo(clip a) Downmix sound functions
# function Dmix4sDpl(clip a) Downmix sound functions
# function Dmix5Stereo(clip a) Downmix sound functions
# function Dmix5Dpl(clip a) Downmix sound functions
# function Dmix5Dpl2(clip a) Downmix sound functions
# function Dmix6Stereo(clip a) Downmix sound functions
# function Dmix6Dpl(clip a) Downmix sound functions
# function Dmix6Dpl2(clip a) Downmix sound functions
# function Dmix6StereoLfe(clip a) Downmix sound functions
# function Dmix6StereoLfe2(clip a) Downmix sound functions
# function Dmix6DplLfe(clip a) Downmix sound functions
# function Dmix6Dpl2Lfe(clip a) Downmix sound functions
#
#

.

Jenyok
1st April 2013, 15:48
There is an error in AVISynth, see atteched file.
.
What must I do in this case ?
.

steptoe
1st April 2013, 16:27
I'm taking a wild guess, as the screenshot is pending approval, but after looking at the script it is loading the soxfilter.dll from a specific folder. If it isn't there then the script WILL fail


Might be better to delete the line below from the script and autoload it by putting it in the avisynth/plugins folder, or to be 100% sure it loads simply copy the soxfilter.dll to where the script is looking for it by default as shown below

LoadPlugin("C:\PROGRAM FILES\AVISYNTH 2.5\PLUGINS\SOXFILTER_11\soxfilter.dll")

Jenyok
3rd April 2013, 10:30
sh0dan
.
I tested SoxFiler and found very strange results of working SoxFilter .
.
See very simple script below.
.

LoadPlugin("C:\PROGRAM FILES\AVISYNTH 2.5\PLUGINS\SOXFILTER_11\soxfilter.dll")
LoadPlugin("C:\PROGRAM FILES\AVISYNTH 2.5\PLUGINS\WAVEFORM_0_2\waveform.dll")

Import("C:\PROGRAM FILES\AVISYNTH 2.5\PLUGINS\REMOVEDIRT\utils2.avsi")

BlankClipNS(length=6250) # Blank clip without sound

audio1=Tone(length=1500, frequency=25, samplerate=44100, channels=1, type="sine", level=0.707) # 0.707=-3dB, 25Hz, 44.1 kHz, MONO 1-channel

audio=audio1

audio1=Normalize(audio1, 1.0) # +0dB, 25Hz, MONO 1-channel
audio1=SoxFilter(audio1, "vol +0.0 dB") # Nothing to do, +0dB, 25Hz, MONO 1-channel

audio=MergeChannels(audio, audio1) # Left=-3dB, 25Hz, Right=+0dB, 25Hz, STEREO 2-channels

AudioDub(last, audio)

waveform()

ConvertToYUY2()

.
See attached file "test01.jpg" as a result of this script.
There are Strange vertical lines in wave form in Right channel (low audio channel in picture).
.
Then I remarked following line, see below code section.
.

#audio1=SoxFilter(audio1, "vol +0.0 dB") # Nothing to do, +0dB, 25Hz, MONO 1-channel

.
See attached file "test02.jpg" as a result of this script without remarked line, see upper code section.
There are no Strange vertical lines in wave form in Right channel (low audio channel in picture).
.

Jenyok
4th April 2013, 13:45
New improvements and changes.
Version 1.4
.
See attached RAR file.
.
.

#
# File: Stereo.avsi
#
#
# Date: 04.04.2013 year
# Version: 1.4
#
#
# License: GNU GENERAL PUBLIC LICENSE
#
#
# Author: Jenyok (Evgeniy Gurovskikh, Russia, Moscow)
# E-Mail: e_gurovskikh@mail.ru
#
#
# Functions (pseudo Stereo and other sound functions) for AVISynth
#
# For all occasions of life (На все случаи жизни) ...
#
#
# Plugin and Import
#
# SoxFilter.dll
#
#
# function PhaseDelay(clip clp, float "freq", float "phi") Shift (rotate) phase of audio to a different angle
# function PhaseShift(clip clp, float "freq", float "phi") Shift (rotate) phase of audio to a different angle
# function PhaseShift2(clip clp, float "freq", float "freq2", float "phi") Shift (rotate) phase of audio to a different angle
#
# function PseudoStereo1(clip clp, int "Channel", float "Delay") Only DELAY between channels, Delay in Sec
# function PseudoStereo12(clip clp, int "Channel", float "Delay", float "KMix") DELAY, L=L*k1+R*k2, R=R*k1+L*k2 (Addition)
# function PseudoStereo13(clip clp, int "Channel", float "Delay", float "KMix") DELAY, L=L*k1-R*k2, R=R*k1-L*k2 (Substraction)
#
# function PseudoStereo2(clip clp, int "Channel", float "LowFreq", float "HighFreq", bool "isDelay")
#
# function PseudoStereo3(clip clp, int "Channel", bool "isDelay") Described: Magazine "Radio" № 6, 1985 year, page 62 (USSR, Russia)
# function PseudoStereo33(clip clp, int "Channel", bool "isDelay") Described: Magazine "Radio" № 6, 1985 year, page 62 (USSR, Russia)
#
# function PseudoStereo4(clip clp, int "Channel", bool "isDelay") US Patent No 6,636,608 B1
# function PseudoStereo43(clip clp, int "Channel", bool "isDelay") US Patent No 6,636,608 B1
#
# function PseudoStereo5(clip clp, int "Channel", bool "isDelay") Analog: Philips chip TDA3810 (sound porcessor)
# function PseudoStereo52(clip clp, int "Channel", bool "isDelay") Analog: Philips chip TDA3810 (sound porcessor)
#
# function StereoEnhancer(clip clp) Analog: Philips chip TDA3810 (sound porcessor)
#
#
# function StereoTo51(clip clp, bool "is24bit") Build 5.1 Sound Audio track from stereo signal,
# 24 bits output (24 bits is a standard ?)
#
#
# function Dmix3Stereo(clip a) Downmix sound functions
# function Dmix3Dpl(clip a) Downmix sound functions
# function Dmix4lStereo(clip a) Downmix sound functions
# function Dmix4qStereo(clip a) Downmix sound functions
# function Dmix4sDpl(clip a) Downmix sound functions
# function Dmix5Stereo(clip a) Downmix sound functions
# function Dmix5Dpl(clip a) Downmix sound functions
# function Dmix5Dpl2(clip a) Downmix sound functions
# function Dmix6Stereo(clip a) Downmix sound functions
# function Dmix6Dpl(clip a) Downmix sound functions
# function Dmix6Dpl2(clip a) Downmix sound functions
# function Dmix6StereoLfe(clip a) Downmix sound functions
# function Dmix6StereoLfe2(clip a) Downmix sound functions
# function Dmix6DplLfe(clip a) Downmix sound functions
# function Dmix6Dpl2Lfe(clip a) Downmix sound functions
#
#

.

Jenyok
8th April 2013, 06:35
sh0dan
.
One more question to you.
.
What string parameters in SoxFilter(...) function for AVISynth could I use to achive following result "Concert Hall Light, No combine sourse Left аnd Right" ?
.
Thanks.

Jenyok
8th April 2013, 13:20
New improvments and changes.
.
There are some functions to convert MONO audio signal to PSEUDO STEREO.
There are some functions to convert STEREO audio signal to 5.1 audio signal.
Added new functions to script.
.
Version 1.5 .
.
See description in code section.
See attached RAR file (LINK).
.

#
# File: Stereo.avsi
#
#
# Date: 08.04.2013 year
# Version: 1.5
#
#
# License: GNU GENERAL PUBLIC LICENSE
#
#
# Author: Jenyok (Evgeniy Gurovskikh, Russia, Moscow)
# E-Mail: e_gurovskikh@mail.ru
#
#
# Functions (pseudo Stereo and other sound functions) for AVISynth
#
# For all occasions of life (На все случаи жизни) ...
#
#
# Plugin and Import
#
# SoxFilter.dll
#
#
#
# function GetLeftChannel(clip clp)
# function GetRightChannel(clip clp)
# function Phase180(clip clp)
#
#
# function PhaseDelay(clip clp, float "freq", float "phi") Shift (rotate) phase of audio to a different angle
# function PhaseShift(clip clp, float "freq", float "phi") Shift (rotate) phase of audio to a different angle
# function PhaseShift2(clip clp, float "freq", float "freq2", float "phi") Shift (rotate) phase of audio to a different angle
#
# function MonoToStereo(clip clp) Convert MONO audio to STEREO audio
# function PseudoStereo1(clip clp, int "Channel", float "Delay") Only DELAY between channels, Delay in Sec
# function PseudoStereo12(clip clp, int "Channel", float "Delay", float "KMix") DELAY, L=L*k1+R*k2, R=R*k1+L*k2 (Addition)
# function PseudoStereo13(clip clp, int "Channel", float "Delay", float "KMix") DELAY, L=L*k1-R*k2, R=R*k1-L*k2 (Substraction)
#
# function PseudoStereo2(clip clp, int "Channel", float "LowFreq", float "HighFreq", bool "isDelay")
#
# function PseudoStereo3(clip clp, int "Channel", bool "isDelay") Described: Magazine "Radio" № 6, 1985 year, page 62 (USSR, Russia)
# function PseudoStereo33(clip clp, int "Channel", bool "isDelay") Described: Magazine "Radio" № 6, 1985 year, page 62 (USSR, Russia)
#
# function PseudoStereo4(clip clp, int "Channel", bool "isDelay") US Patent No 6,636,608 B1
# function PseudoStereo43(clip clp, int "Channel", bool "isDelay") US Patent No 6,636,608 B1
#
# function PseudoStereo5(clip clp, int "Channel", bool "isDelay") Analog: Philips chip TDA3810 (sound porcessor)
# function PseudoStereo52(clip clp, int "Channel", bool "isDelay") Analog: Philips chip TDA3810 (sound porcessor)
#
#
# function StereoEnhancer(clip clp) Analog: Philips chip TDA3810 (sound porcessor)
#
#
# function StereoTo51(clip clp, bool "is24bit", bool "isStereo") Convert STEREO to 5.1 audio, 24 bits output
#
# function UpDialog(clip clp) Convert STEREO to 5.1 audio
# function UpDialog2(clip clp) Convert STEREO to 5.1 audio
# function UpAction(clip clp) Convert STEREO to 5.1 audio
# function UpAction2(clip clp) Convert STEREO to 5.1 audio
# function UpGerzen(clip clp) Convert STEREO to 5.1 audio
# function UpFarina(clip clp) Convert STEREO to 5.1 audio
# function UpMultisonic(clip clp) Convert STEREO to 5.1 audio
# function UpSoundOnSound(clip clp) Convert STEREO to 5.1 audio
#
#
# function Dmix3Stereo(clip a) Downmix sound functions
# function Dmix3Dpl(clip a) Downmix sound functions
# function Dmix4lStereo(clip a) Downmix sound functions
# function Dmix4qStereo(clip a) Downmix sound functions
# function Dmix4sDpl(clip a) Downmix sound functions
# function Dmix5Stereo(clip a) Downmix sound functions
# function Dmix5Dpl(clip a) Downmix sound functions
# function Dmix5Dpl2(clip a) Downmix sound functions
# function Dmix6Stereo(clip a) Downmix sound functions
# function Dmix6Dpl(clip a) Downmix sound functions
# function Dmix6Dpl2(clip a) Downmix sound functions
# function Dmix6StereoLfe(clip a) Downmix sound functions
# function Dmix6StereoLfe2(clip a) Downmix sound functions
# function Dmix6DplLfe(clip a) Downmix sound functions
# function Dmix6Dpl2Lfe(clip a) Downmix sound functions
#
#

.
http://forum.doom9.org/attachment.php?attachmentid=13392&d=1365423562

der_andi
20th May 2013, 14:47
Hi sh0dan,

there's a small problem with compand. I am using the compand filter in an *.avs for compressing the dynamic range of an audio file. The AVS file is then processed via MeGUI. The relevant script line:

SoxFilter("compand 0.3,1 6:-70,-60,-20 -8 -90 0.2")

The error message in the MeGUI log says:


SoxFilter: (compand) Parameter error:
compander: Odd number of transfer function parameters
Each input value in dB must have a corresponding output value.


As I don't want to compress levels below -70, I omit the first dbOut parameter. But even when I set it to -70, it just says:
dB values are relative to maximum input, and, ipso facto, cannot exceed 0

I must admit, I don't know, what the last message means. Am I doing something wrong here or is this a bug in the filter?


Kind regards,
Andi

speedyrazor
29th July 2015, 06:48
Hi, I am wanting to change the tempo of an audio file in avisynth but keep the same pitch, is this possible with this plugin, if so, where can I download the latest avisynth plugin version please?

Kind regards.

Gavino
29th July 2015, 08:12
I am wanting to change the tempo of an audio file in avisynth but keep the same pitch
You can do this with the built-in Avisynth function TimeStretch() (http://avisynth.nl/index.php/TimeStretch), using the tempo parameter.

Great for slowing down fast guitar solos to work out how to play them!

speedyrazor
29th July 2015, 08:26
The built-in Avisynth function TimeStretch() is not multi-channel aware, so is not good if you have 6 monos and a stereo, for example, the resulting file sounds all 'phasey'.

manolito
29th July 2015, 15:53
Hi, I am wanting to change the tempo of an audio file in avisynth but keep the same pitch, is this possible with this plugin, if so, where can I download the latest avisynth plugin version please?

Kind regards.

AFAIK version 1.1 beta from 2006 is the latest.

It is quite old, and for your intended purpose the newer SoX effect "tempo" is not included in the plugin. Instead you would have to use the "stretch" effect which has much poorer quality (according to the SoX manual).

If you want to use SoX you should export the audio from the AVS using avs2pipemod or Wavi and then process the WAV file using SoX.exe directly.


Cheers
manolito

thescrapyard
2nd August 2015, 20:22
I use AVStoDVD for converting pretty much any video file to DVD using HCEnc and uses AviSynth, but it doesn't support any kind of upsampling for audio sources to 5.1, but does support downsampling

I've tried understanding how to use sox within avisynth scripts but still can't get to grips the commands needs for sox to process a 2-channel source to pseudo 5.1 audio


If anybody can point me in the right direction how to integrate sox and the script would help me out


The basic avisynth script layout is pretty much standard :

Import("C:\Program Files (x86)\Applications\Video\AVstoDVD\Lib\A2DSource.avsi")
LoadPlugin("C:\Program Files (x86)\Applications\Video\AVstoDVD\Lib\ffms2.dll")

Audio = FFAudioSource("L:\testvideo.avi", track=1)
Video = A2DVideoSource("L:\testvideo.avi", CacheFolder="C:\Temp-AVStoDVD", FrameRateNum=25, FrameRateDen=1, FrameRate=25.000)

Audio = Audio.SSRC(48000) ## Just examples of the audio commands and how they are used to change the audio
Audio = Audio.DelayAudio(0) ##
Audio = Audio.AmplifyDB(0) ##

AudioDub(Video, Audio)


This is the script I'm trying to use :


Import("C:\Program Files (x86)\Applications\Video\AVstoDVD\Lib\A2DSource.avsi")
LoadPlugin("C:\Program Files (x86)\Applications\Video\AVstoDVD\Lib\ffms2.dll")

LoadPlugin("C:\Program Files (x86)\Applications\Video\AVstoDVD\Lib\soxfilter.dll")
Import("C:\Program Files (x86)\Applications\Video\AVstoDVD\Lib\stereo.avsi")


Audio = FFAudioSource("L:\testvideo.avi", track=1)
Video = A2DVideoSource("L:\testvideo.avi", CacheFolder="C:\Temp-AVStoDVD", FrameRateNum=25, FrameRateDen=1, FrameRate=25.000)

## video filters ##

Video = Video.ConvertToYV12()
Video = Video.AddBorders(0,34,0,34)
Video = Video.Spline36Resize(720,576)

## audio filters ##

Audio = Audio.SSRC(48000) ## Just examples of the audio commands and how they are used to change the audio
Audio = Audio.DelayAudio(0) ##
Audio = Audio.AmplifyDB(0) ##


#######################
## sox 2 channel to 5.1
#######################

audio = audio.stereoenhancer()
audio = audio.upaction()



AudioDub(Video, Audio)

manolito
8th August 2015, 01:19
#######################
## sox 2 channel to 5.1
#######################

audio = audio.stereoenhancer()
audio = audio.upaction()



It is not hard to use these functions, but all I get from using them is a terribly distorted 6-ch audio track... :o

Replace your upmix commands with the following:
Last = Audio
# stereoenhancer()
Upaction()
Audio = Last

Jenyok's stereo.avsi has a hard coded command at the beginning to load SoxFillter.dll, make sure to delete this line if you load the dll manually.

I tried all the different upmix functions from stereo.avsi, but the result was always distorted. No idea if the culprit lies within SoxFilter.dll or if the MergeChannels(..) command is to blame - I suspect that SoxFilter is the reason.


If you want to check out the script within AVStoDVD keep in mind that the requirements of my Wavi_Mod plugin do also apply, and these are:

1. Make sure that the DirectShow Audio Mixer does not get in the way (disable the audio mixer plus under "Preferences/Misc" make sure that A2S does not alter the mixer settings at runtime.

2. After loading the source edit the title properties and change the number of channels from 2 to 6.

3. Under "View/Edit Title settings / Audio" uncheck auto settings and choose a bitrate of 448 kbps.


Other things to note:
If you use AviSynth normalizing move this command to a position after upmixing. Put it right before the AudioDub command.
With this script the preview will not have audio (at least on my computer).


My conclusion:
Upmixing within AviSynth just does not work. Do the upmixing outside of AviSynth using the Wavi_Mod plugin.


Cheers
manolito

tebasuna51
8th August 2015, 14:08
About stereoenhancer()

Of course is not recommended before Upaction(), stereoenhancer() convert a stereo audio (FL,FR) in another (FL',FR') with:

FL' = Normalize(Normalize(FL,1) + Normalize(SoxFilter(Normalize(FR,1), BandPass 3500 2000), 0.66), 1)
FR' = Normalize(Normalize(FR,1) + Normalize(SoxFilter(Normalize(FL,1), BandPass 3500 2000), 0.66), 1)

Thats enhance only the voice frequencies adding this frequencies from FR to FL and viceversa. But:

1) Destroy original balance normalizing separately FL and FR. Normalice always stereo.
2) Destroy stereo effect in voice frequencies mixing FL and FR.
3) Can produce peak clips when mix (add) integer samples with peaks at 1 and 0.66 dB. Before that mix convert to float samples and after Normalize and convert to integer.

Suggested changes to enhance vocal frequencies:

Vocal = SoxFilter(Input, BandPass 3500 2000).ConvertAudioTofloat()
Input = ConvertAudioTofloat(Input)
MixAudio(Input, Volcal, 1.0, 0.66).Normalice().ConvertAudioTo16bit()

About Upmix functions

I can't understand how the mixes between FL and FR can produce a coherent upmix. Only the UpSoundOnSound function have some sense for me.

BTW remember ConvertAudioTofloat before mix and after normalize.
Also I recommend use always a empty LFE channel, for instance:

lfe = GetLeftChannel(a).Amplify(0)

manolito
8th August 2015, 16:34
Thanks tebasuna for the tips, much appreciated.

But it still does not fix the main problem which is distorted output no matter which upmix method is used.

BTW my previous statement that this calling format
Last = Audio
Upaction()
Audio = Last
must be used was wrong. As soon as the "loadplugin" line for SoxFilter is removed from stereo.avsi you can call the upmix function like you did:
audio = audio.upaction()

This does also work:
upaction(Audio)
Audio = Last


Cheers
manolito

tebasuna51
8th August 2015, 20:40
But it still does not fix the main problem which is distorted output no matter which upmix method is used.

- I never recommend upmix 2.0 to 5.1, use DSP functions of amplifier/receiver at play time to do the job.

- If still want upmix I recommend the method http://forum.doom9.org/showthread.php?p=768141#post768141

- I can't recommend AviSynth methods, not always work like desired.

manolito
8th August 2015, 22:47
I do not even have a multichannel Home Theater setup, the only reason I got into this was a request by steptoe (thescrapyard) to integrate this function into AVStoDVD... ;)

Selur translated Northpole's methods for use with SoX here:
http://forum.doom9.org/showthread.php?p=1385573#post1385573

and this works fine within my Wavi_Mod plugin for AVStoDVD. The same method using SoxFilter causes distortion, and I have no idea why. :confused:

BTW you mentioned that only the SoundOnSound method makes sense to you. Since I cannot test the results, do you think that this method is "more universal" than the other methods? If so I would add it to my plugin.


Cheers
manolito

tebasuna51
9th August 2015, 13:29
Selur translated Northpole's methods for use with SoX here:
http://forum.doom9.org/showthread.php?p=1385573#post1385573

and this works fine within my Wavi_Mod plugin for AVStoDVD. The same method using SoxFilter causes distortion, and I have no idea why. :confused:

Maybe because first Selur pass is "lower volume to avoid clipping" and next mixes don't clip peaks. AviSynth functions from Jenyok mix int samples and can distort sources with high volume.

The clip can be avoided also using float samples and a final Normalize and Convert to int samples (if necesary, some encoders support float samples).

BTW you mentioned that only the SoundOnSound method makes sense to you. Since I cannot test the results, do you think that this method is "more universal" than the other methods? If so I would add it to my plugin.

Well, all (except SoundOnSound) have the same method (with different coeficients cx) to construct the front channels. A input stereo source (FLi,FRi) produce a surround output (FLo,FRo,FCo,...) with:

FLo = mixaudio(FLi, FRi, c1, -c1)
FRo = mixaudio(FRi, FLi, c1, -c1)
FCo = mixaudio(mixaudio(FLi, FLo, 1.0, -1.0), mixaudio(FRi, FRo, 1.0, -1.0), c2, c2)

Like you can see FLo = -FRo, and only the diferences between FLi and FRi are sended to front speakers.

The FCo mix is a trap, seems mix the common parts between FLi and FRi but is not true because:
Fco = c2 * ((FLi - FLo) + (FRi - FRo))
= c2 * ((FLi - c1 * (FLi - FRi)) + (FRi - c1 * (FRi - FLi)))
= c2 * (FLi - c1 * FLi + c1 * FRi + FRi - c1 * FRi + c1 * FLi)
= c2 * (FLi + FRi)

Is equivalent to:
FCo = mixaudio(FLi, FRi, c2, c2)

All audio is sended to the FC speaker. That can cause, for me, two problems:

1) When Normalize (or using low coeficient c2) the overall volume can decrease (only one speaker FC must play the volume than before play two speakers).

2) Many audio systems have the FL-FR speakers better than FC speaker and the overall quality of sound can be reduced.

Like UpSoundOnSound preserve the front channels untouched is my better option.

manolito
10th August 2015, 00:49
Maybe because first Selur pass is "lower volume to avoid clipping" and next mixes don't clip peaks. AviSynth functions from Jenyok mix int samples and can distort sources with high volume.

The clip can be avoided also using float samples and a final Normalize and Convert to int samples (if necesary, some encoders support float samples).



Hi tebasuna,

I had already tried to lower the volume and use float input to avoid clippimg, but to no avail. The resulting audio track always had some crackling static noise in it, I have given up on SoxFilter...


In the meantime I have added the SoundOnSound method to my plugin, and the only question I have is about the center channel. The original script uses:
cc = mixaudio(a.GetRightChannel(), a.GetLeftChannel(), 0.5, 0.5)
which seems awfully loud. For now I have reduced the mix coefficients to 0.375 per channel, but I wonder if it would not be better to use a method for the center channel which eliminates the stereo content (to a degree) like the UpAction method does.


Cheers
manolito

tebasuna51
10th August 2015, 12:50
I had already tried to lower the volume and use float input to avoid clippimg, but to no avail. The resulting audio track always had some crackling static noise in it, I have given up on SoxFilter...


I make some test and I can confirm the bug detected by Jenyok here:
http://forum.doom9.org/showthread.php?p=1622520#post1622520

Using:
back = soxfilter(a, "filter 100-7000")

There are buggy samples, when reach 0dB invert the sign, than can produce crackling. Then I can't recommend the use of this plugin without low the volume of the source before.

tebasuna51
10th August 2015, 16:07
Upmix with AviSynth

1) Main problem Center channel.
A correct FC channel must have the comon parts from FL-FR channels in vocal frequencies, but I don't know how extract the common parts using standard AviSynth functions.
The best option, for me, is not create FC. Let FC like phantom channel, when listen a stereo the common parts are listened like there are a FC present.

2) Useless LFE channel.
When a audio system have subwoofer all bass frequencies from all channels are sended to subwoofer.
Don't mistake LFE (Low Frequency Effects) channel with subwoofer, all bass frequencies from FL-FR are sended to subwoofer (if present).
Extract low frequencies to LFE is useless and maybe dangerous.

3) Surround Channels.
Seems a good idea send to surround channels the difference bewteen Front Channels:
- Don't disturb the phantom FC
- Apply a bandpass filter ("filter 120-7000") maybe is unnecesary because many times the low frequencies are cancelled when substract FL - FR.
Also a Delay is recommended.

For instance:
a = xSource("stereo file")
sl = mixaudio(GetLeftChannel(a), GetRightChannel(a), 0.5, -0.5) # max 0.5 to avoid clip (1)
sr = mixaudio(GetRightChannel(a), GetLeftChannel(a), 0.5, -0.5)
sl = DelayAudio(sl, 0.02)
sr = DelayAudio(sr, 0.02)
MergeChannels(a, sl, sr) # for Quadrasonic output

If you need 5.1 compatibility add:

c_lfe = Amplify(a, 0)
MergeChannels(a, c_lfe, sl, sr)

(1) Many times the difference between channels have low volume, you can increase the coeficients at your risk or better:
surr = MergeChannels(sl, sr).Normalize(0.7) # or the desired surround volume
MergeChannels(a, c_lfe, surr)

manolito
10th August 2015, 23:46
Thanks again Tebasuna.

I tested your AviSynth script for upmixing, and the elimination of SoxFilter does get rid of the distortion. Since I cannot test the results (I do not own a surround system), I made an AVSI with 3 "UpTebasuna" functions:

UpTebasuna.avsi
function UpTebasuna(clip clp)
{
a = KillVideo(clp)
lfe = Amplify(a, 0)
sl = mixaudio(GetLeftChannel(a), GetRightChannel(a), 0.473, -0.473) # max 0.5 to avoid clip
sr = mixaudio(GetRightChannel(a), GetLeftChannel(a), 0.473, -0.473)
sl = DelayAudio(sl, 0.02)
sr = DelayAudio(sr, 0.02)
surr = MergeChannels(sl, sr) # .Normalize(0.7)
return (MergeChannels(a, lfe, surr))
}


function UpTebasuna2(clip clp)
{
a = KillVideo(clp)
lfe = GetLeftChannel(a).Amplify(0)
cc = mixaudio(GetRightChannel(a), GetLeftChannel(a), 0.375, 0.375)
sl = mixaudio(GetLeftChannel(a), GetRightChannel(a), 0.473, -0.473) # max 0.5 to avoid clip
sr = mixaudio(GetRightChannel(a), GetLeftChannel(a), 0.473, -0.473)
sl = DelayAudio(sl, 0.02)
sr = DelayAudio(sr, 0.02)
surr = MergeChannels(sl, sr) # .Normalize(0.7)
return (MergeChannels(a, cc, lfe, surr))
}


function UpTebasuna3(clip clp)
{
a = KillVideo(clp)
lfe = GetLeftChannel(a).Amplify(0)
fl = mixaudio(GetLeftChannel(a), GetRightChannel(a), 0.668, -0.668)
fr = mixaudio(GetRightChannel(a), GetLeftChannel(a), 0.668, -0.668)
cc = mixaudio(mixaudio(GetLeftChannel(a), fl, 1.0, -1.0), mixaudio(GetRightChannel(a), fr, 1.0, -1.0), 0.398, 0.398)
sl = mixaudio(GetLeftChannel(a), GetRightChannel(a), 0.473, -0.473) # max 0.5 to avoid clip
sr = mixaudio(GetRightChannel(a), GetLeftChannel(a), 0.473, -0.473)
sl = DelayAudio(sl, 0.02)
sr = DelayAudio(sr, 0.02)
surr = MergeChannels(sl, sr) # .Normalize(0.7)
return (MergeChannels(a, cc, lfe, surr))
}

The only difference between them is the treatment of the center channel. (The LFE channel is empty for all three functions).

The first one has an empty center channel like you proposed, the second one has a simple mono channel from fl and fr at a level of 0.75, and the third function constructs the center channel like the "UpAction" method.

I am mainly interested how the third function sounds regarding the center channel. It would be nice if someone with a good quality home theater system could test this using some real world stereo material...


Cheers
manolito

tebasuna51
11th August 2015, 11:40
I am mainly interested how the third function sounds regarding the center channel.
Like I say before

cc = mixaudio(mixaudio(GetLeftChannel(a), fl, 1.0, -1.0), mixaudio(GetRightChannel(a), fr, 1.0, -1.0), 0.398, 0.398)

is the same, little different coeficient, than

cc = mixaudio(GetRightChannel(a), GetLeftChannel(a), 0.375, 0.375)

Tested with a 24 bits wav and same coeficient (0.398 for both), the differences are only rounding bits at -138.47dB.

manolito
11th August 2015, 19:32
Thanks, I went over your math again, and of course you are right about the center channel.

After some research I found a method to create a "correct" center channel. It is called "CenterCut" by Avery Lee and it is part of VirtualDub. Moitah also made a WinAmp DSP from it.

But so far I do not see a way to use this from within AviSynth. Of course AviSynth can use VDF plugins, but CenterCut does not come as a separate plugin, it is integrated into VDub. And using WinAmp DSPs in AviSynth has been discussed a few times, but I did not find a working solution.

Since it is open source, maybe one of the AviSynth plugin developers will find the time some day to write a native AviSynth plugin...


Cheers
manolito

Wilbert
11th August 2015, 21:28
The plugin uses the Sox library 12.17.9 from 2006. Did you guys check out whether the upmixing problems still exists today (in 14.4.2 for example)? Otherwise we should update the library to solve those issues. Updating it would be a good idea anyway ...

manolito
11th August 2015, 22:13
I have been using SoX 14.4.1 for some time to upmix stereo to 6-ch outside of AviSynth. No problems...

But having a newer SoxFilter plugin would still not solve the problem how to create a correct center channel.


Cheers
manolito

tebasuna51
11th August 2015, 22:21
The effect 'filter' was replaced by 'sinc' effect in sox-14.4.0. Using sox-14.4.2

sox input.wav output.wav sinc 100-7000

work fine with the same wav than soxfilter(a, "filter 100-7000") have the bug in the my previous post (attached image)

tebasuna51
11th August 2015, 23:37
Since it is open source, maybe one of the AviSynth plugin developers will find the time some day to write a native AviSynth plugin...
+1

There are sources for DSP plugin and command line:
http://www.moitah.net/download/latest/dsp_centercut.zip
http://www.moitah.net/download/latest/Center_Cut_GUI-Source.zip
http://www.moitah.net/download/latest/Center_Cut_GUI.zip

By the moment you can use also:
CenterCutCL input.wav -s FLFR.wav -c FC.wav -b