View Full Version : BeHappy - AviSynth based audio transcoding tool (UPD 19-07-2006)
CoRoNe
10th February 2012, 20:07
tebasuna has already explained in post #995 why this will not work:My apologies.
The working directory will be the one containing the script, not the audio file.Having tak_deco_lib.dll in either directory won't let you decode tak-files. Just tested it.
To summarize the workarounds to decode OptimFROG or TAK that do work:
- put OptimFROG.dll and tak_deco_lib.dll in the app's directory (MPC-HC's directory for instance if you open the Avisynth script with it).
- put OptimFROG.dll and tak_deco_lib.dll in the Windows\System32 directory.
- add the plugins directory to the Windows Environment System Variables, so Windows can search that directory if external libraries are needed and will use them automatically. (Windows key+Pause, "Advanced"-tab, "Environment Variables", "System Variables", click "Path", Edit, at the end add the full path of the plugins directory with a preceding semicolon (';'))
- use tsp's LoadDll Avisynth plugin (http://www.avisynth.org/tsp/LoadDll.zip). Insert LoadDll("path\tak_deco_lib.dll") before Loadplugin("path\BassAudio.dll")!
tebasuna51
11th February 2012, 11:04
...
However, I'm not sure what you (tebasuna) mean by "AviSynth set the working directory to the directory of the sample to decode". The working directory will be the one containing the script, not the audio file.
You are rigth, maybe I simplified the explain because the problem is the same, to have the ext dll's in .avs directory or sample file directory don't help CoRoNe requirements.
With my test with wavi and a .avs file, work fine with a ext-dll copy in "plugins" directory and other in .avs directory or in sample file directory.
And using BeHappy the .avs is created in a temp user directory (GetTempPath), under user Documents and Settigns, more difficult to use than sample directory.
BTW, I edit my previous post to be more exact.
CoRoNe
15th February 2012, 13:00
I'm resigning myself with this issue. LoadDll it's gonna be until someday perhaps bass_ofr.dll and bass_tak.dll will search for external Dlls in the plugins directory first.
Something completely different now...
In the past I've always used BeSweet in combination with BeLight to do 5.1 AC3 to DPLII <audio-format> conversions. Lately I've been experimenting with Foobar, foo_input_avs (to load Avisynth scripts) and several DSPs, but I wasn't satisfied with the results. Before Foobar I already knew BeHappy could do the same thing more or less, but yesterday I really dug into it;
I noticed BeHappy uses another DPLII matrix (http://forum.doom9.org/showthread.php?p=1464705#post1464705), compared to the official one (https://en.wikipedia.org/wiki/Matrix_decoder#Dolby_Pro_Logic_II_matrix_encoding_.282:5.29), which has been discussed here (http://forum.doom9.org/showthread.php?t=105869) amongst other threads.
Now if I understand correctly how to derive a DPLII matrix's coefficients (http://forum.doom9.org/showthread.php?p=145721#post145721), and I did my calculations correctly in the draft below, those numbers have to correspond with the official DPLII matrix, don't they?
Draft with calculations I made in notepad yesterday:
BeHappy DPL2 matrix:
Lt = 1.0L + 0.7071(√½)*C + 0.8660(√¾)*Ls + 0.5000(√¼)*Rs 1 + 0.7071 + 0.8660 + 0.5000 = 3.0731
Rt = 1.0R + 0.7071(√½)*C - 0.5000(√¼)*Ls - 0.8660(√¾)*Rs 1 / 3.0731 = 0.3254
function Dmix6Dpl2(clip a) {
flr = GetChannel(a, 1, 2)
fcc = GetChannel(a, 3, 3)
lrc = MixAudio(flr, fcc, 0.3254, 0.2301) 0.3254, (0.3254*0.7071)
bl = GetChannel(a, 5)
br = GetChannel(a, 6)
sl = MixAudio(bl, br, 0.2818, 0.1627) (0.3254* 0.8660), (0.3254* 0.5000)
sr = MixAudio(bl, br, -0.1627, -0.2818) (0.3254*-0.5000), (0.3254*-0.8660)
blr = MergeChannels(sl, sr)
return MixAudio(lrc, blr, 1.0, 1.0)
}
=====================================================================================================
Official DPL2 matrix:
Lt = 1.0L + 0.7071(√½)*C - 0.8165(√⅔)*Ls - 0.5774(√⅓)*Rs 1 + 0.7071 + 0.8165 + 0.5774 = 3.1010
Rt = 1.0R + 0.7071(√½)*C + 0.5774(√⅓)*Ls + 0.8165(√⅔)*Rs 1 / 3.1010 = 0.3225
function Dmix6Dpl2(clip a) {
flr = GetChannel(a, 1, 2)
fcc = GetChannel(a, 3, 3)
lrc = MixAudio(flr, fcc, 0.3225, 0.2280) 0.3225, (0.3225*0.7071)
bl = GetChannel(a, 5)
br = GetChannel(a, 6)
sl = MixAudio(bl, br, -0.2633, -0.1862) (0.3225*-0.8165), (0.3225*-0.5774)
sr = MixAudio(bl, br, 0.1862, 0.2633) (0.3225* 0.5774), (0.3225* 0.8165)
blr = MergeChannels(sl, sr)
return MixAudio(lrc, blr, 1.0, 1.0)
}
=======================================================================================================================
Official DPL2+LFE matrix:
Lt = 1.0L + 0.7071(√½)*C + 0.7071(√½)*LFE - 0.8165(√⅔)*Ls - 0.5774(√⅓)*Rs 1 + 2*0.7071 + 0.8165 + 0.5774 = 3.8081
Rt = 1.0R + 0.7071(√½)*C + 0.7071(√½)*LFE + 0.5774(√⅓)*Ls + 0.8165(√⅔)*Rs 1 / 3.8081 = 0.2626
function Dmix6Dpl2Lfe(clip a) {
flr = GetChannel(a, 1, 2)
fcc = GetChannel(a, 3, 3)
lrc = MixAudio(flr, fcc, 0.2626, 0.1857) 0.2626, (0.2626*0.7071)
lfe = GetChannel(a, 4, 4)
lrc = MixAudio(lrc, lfe, 1.0, 0.1857) (0.2626*0.7071)
bl = GetChannel(a, 5)
br = GetChannel(a, 6)
sl = MixAudio(bl, br, -0.2144, -0.1516) (0.2626*-0.8165), (0.2626*-0.5774)
sr = MixAudio(bl, br, 0.1516, 0.2144) (0.2626* 0.5774), (0.2626* 0.8165)
blr = MergeChannels(sl, sr)
return MixAudio(lrc, blr, 1.0, 1.0)
}
Now, as I'm unsatisfied with Foobar's Dynamics Compressor, I'd like to do BeSweet.exe -azid(-s dplii -c normal -L -3db --maximize) -ota(-hybridgain) (which I've been using a lot in the past if I remember correctly) with Avisynth. Please tell me, am I getting close?:
NicDTSSource("FileName.dts", DRC=1) # -azid(-c normal)
ConvertAudioToFloat()
flr = GetChannel(1, 2)
fc = GetChannel(3, 3)
lrc = MixAudio(flr, fc, 0.2626, 0.1857)
lfe = GetChannel(4, 4)
lrc = MixAudio(lrc, lfe, 1.0, 0.1857)
-----------------------------------------
lfe = GetChannel(4, 4).AmplifydB(-3.0) # -azid(-L -3db), or would this totally screw-up the DPLII-matrix?
lrc = MixAudio(lrc, lfe, 1.0, 1.0)
-----------------------------------------
bl = GetChannel(5)
br = GetChannel(6)
sl = MixAudio(bl, br, -0.2144, -0.1516)
sr = MixAudio(bl, br, 0.1516, 0.2144)
blr = MergeChannels(sl, sr)
MixAudio(lrc, blr, 1.0, 1.0) # -azid(-s dplii)
Normalize() # -azid(--maximize)
AmplifydB(10) # -ota(hybridgain), I just picked a number (dB), because I don't
# know what would be equivalent to hybridgain.
P.s. Although I believe this (https://en.wikipedia.org/wiki/Matrix_decoder#Dolby_Pro_Logic_II_matrix_encoding_.282:5.29) is the official DPLII matrix, it's strange this (https://en.wikipedia.org/wiki/Dolby_Pro_Logic#Dolby_encoding_matrices) one is also mentioned on wikipedia...
tebasuna51
16th February 2012, 00:54
I'd like to do BeSweet.exe -azid(-s dplii -c normal -L -3db --maximize) -ota(-hybridgain) with Avisynth.
Here -hybridgain do nothing because the audio was already normalized by azid parameter --maximize.
Please tell me, am I getting close?:
...
lfe = GetChannel(4, 4)
lrc = MixAudio(lrc, lfe, 1.0, 0.1857)
-----------------------------------------
lfe = GetChannel(4, 4).AmplifydB(-3.0) # -azid(-L -3db), or would this totally screw-up the DPLII-matrix?
lrc = MixAudio(lrc, lfe, 1.0, 1.0)
-----------------------------------------
You can't add two times LFE, the first one is enough to complain -azid(-L -3db)
...
Normalize() # -azid(--maximize)
AmplifydB(10) # -ota(hybridgain), I just picked a number (dB), because I don't
# know what would be equivalent to hybridgain.
Like I say before -ota(hybridgain) do nothing with a normalized audio. With this syntax you clip all sound over -10 dB and distort the output.
CoRoNe
16th February 2012, 12:01
It was only just a draft, not heeding the syntax that much. Perhaps I should've put brackets in front of it, because obviously I didn't mean to invoke both LFE lines at the same time:
lfe = GetChannel(4, 4)
lrc = MixAudio(lrc, lfe, 1.0, 0.1857)
#-----------------------------------------
#lfe = GetChannel(4, 4).AmplifydB(-3.0) # -azid(-L -3db), or would this totally screw-up the DPLII-matrix?
#lrc = MixAudio(lrc, lfe, 1.0, 1.0)
#-----------------------------------------But if you say, -azid(-L -3dB) is already incorporated in the matrix, then I'll just delete the line of course.
Strange, as far as I can remember, there was a guide years ago, that recommended that specific BeSweet command-line, and a lot of people used that guide. Strange then, because I can indeed confirm it doesn't do anything (filesize stays the same) when I remove -ota(hybridgain) from BeSweet's command-line. In that case, I think it's save to use the following script for AC3 audio then:
NicAC3Source("FileName.ac3", DRC=1) NicDTSSource("FileName.dts", DRC=1) # -azid(-c normal)
ConvertAudioToFloat() ConvertAudioToFloat()
flr = GetChannel(a, 1, 2) flr = GetChannel(a, 1, 2)
fc = GetChannel(a, 3, 3) fc = GetChannel(a, 3, 3)
lrc = MixAudio(flr, fc, 0.2626, 0.1857) lrc = MixAudio(flr, fc, 0.2626, 0.1857)
lfe = GetChannel(a, 4, 4) lfe = GetChannel(a, 4, 4)
lrc = MixAudio(lrc, lfe, 1.0, 0.1857) lrc = MixAudio(lrc, lfe, 1.0, 0.1857) # -azid(-L -3db)
bl = GetChannel(a, 5) bl = GetChannel(a, 5)
br = GetChannel(a, 6) br = GetChannel(a, 6)
sl = MixAudio(bl, br, -0.2144, -0.1516) sl = MixAudio(bl, br, 0.2144, 0.1516) # Phase Shift for DTS(?)
sr = MixAudio(bl, br, 0.1516, 0.2144) sr = MixAudio(bl, br, -0.1516, -0.2144)
blr = MergeChannels(sl, sr) blr = MergeChannels(sl, sr)
MixAudio(lrc, blr, 1.0, 1.0) MixAudio(lrc, blr, 1.0, 1.0) # -azid(-s dplii)
Normalize() Normalize() # -azid(--maximize)http://www.ld-host.de/uploads/thumbnails/5eb323c177234a06887e6879e2816c3f.png (http://www.ld-host.de/show/5eb323c177234a06887e6879e2816c3f.png)
(Foobar Downmix AC3/DTS to DPL2 plugin)
And what about 90° Phase Shifting for DTS audio? I noticed BeHappy uses the same matrix for AC3 and DTS, but shouldn't I apply the code above to DTS audio, or is this completely wrong and unnecessary?
P.s. I assume my matrix calculations earlier were correct :p
tebasuna51
17th February 2012, 04:00
- You don't need ConvertAudioToFloat(), The output from NicAc3/DtsSource is already float.
- Dolby don't recommend use LFE in DPL II
- I don't recommend use Phase Shift with encoded data source (even DTS). Change the signs is not equivalent to use Phase Shift.
I don't know any AviSynth function to change audio phase.
- You are free to try any downmix that you want. But if you ask me the correct downmix matrix is the included already in BeHappy.
CoRoNe
17th February 2012, 17:11
AudioDub(Blankclip(),NicDtsSource("test.dts"))
b = (IsAudioFloat==true) ? String(" float") : String(" int")
Subtitle(String(AudioBits) + "bit" + b)
- "32bit float" indeed. :p Didn't know that.
- I've read about it, yes. Though I believe everyone does it anyway, right?
- BeSweet doesn't have PhaseShift settings either I believe. It's only the Downmix AC3/DTS to DPL2 plugin for Foobar, so I guess it's not that important.
- I'll certainly give it a try.
Btw, I just came to realize; you mentioned "downmix matrix"...
Lt = 1.0*L + 0.7071*C + 0.7071*LFE - 0.8165*Ls - 0.5774*Rs
Rt = 1.0*R + 0.7071*C + 0.7071*LFE + 0.5774*Ls + 0.8165*Rs
Lt = 0.2626*L + 0.1857*C + 0.1857*LFE - 0.2144*Ls - 0.1516*Rs
Rt = 0.2626*R + 0.1857*C + 0.1857*LFE + 0.1516*Ls + 0.2144*Rs
Then the first one is probably called "upmix matrix"?
======================================================
Something different (again)...
Yesterday I noticed that for PAL,NTSC conversions BeHappy uses (AudioRate()*1001+480)/960) instead of the imo more obvious (AudioRate()*1001/24000)*25), so I (again) did some testing:
#NicDtsSource("test.dts") #48000Hz 6ch 1536kbps, 32bit float | NTSC->PAL, 2:00.075s->1:55.157s
#AssumeSampleRate(last, (AudioRate()*1001/24000)*25).SSRC(AudioRate(last)) #48000->50050.0000 | 50050 (1:55.157s)
#AssumeSampleRate(last, (AudioRate()*1001+480)/960).SSRC(AudioRate(last)) #48000->50050.5000 | 50050 (1:55.157s)
#NicAc3Source("test.ac3") #48000Hz 6ch 448kbps, 32bit float | PAL->NTSC, 2:00.000s->2:05.125s
#SSRC(last, (AudioRate()*1001/24000)*25).AssumeSampleRate(AudioRate(last)) #48000->50050.0000 | 50050 (2:05.125s)
#SSRC(last, (AudioRate()*1001+480)/960).AssumeSampleRate(AudioRate(last)) #48000->50050.5000 | 50050 (2:05.125s)
#WavSource("test_dts.wav") #44100Hz 2ch 1411kbps, 16bit int | NTSC->PAL, 2:00.075s->1:55.157s
#AssumeSampleRate(last, (AudioRate()*1001/24000)*25).SSRC(AudioRate(last)) #44100->45983.4375 | 45975 (1:55.178s)
#AssumeSampleRate(last, (AudioRate()*1001+480)/960).SSRC(AudioRate(last)) #44100->45983.9375 | 45983 (1:55.158s)
WavSource("test_ac3.wav") #44100Hz 2ch 1411kbps, 16bit int | PAL->NTSC, 2:00.000s->2:05.125s ¹
ConvertAudioToFloat()
#SSRC(last, (AudioRate()*1001/24000)*25).AssumeSampleRate(AudioRate(last)) #44100->45983.4375 ² | 45975 (2:05.102s) ³
SSRC(last, (AudioRate()*1001+480)/960).AssumeSampleRate(AudioRate(last)) #44100->45983.9375 | 45983 (2:05.124s)
¹ <original length> -> <length it should be after conversion>
² <original frequency> -> <frequency it should be after conversion, without SSRC()>
³ <reported frequency> <reported length> (by Foobar and foo_input_avs)
Both formulas produce the same result for DTS and AC3, but for 44.1kHz 2ch 1411kbps WAV it's a whole different story!
Both aren't millisecond accurate, not even (AudioRate()*1001+480)/960), but I really don't understand the reported 45975Hz in the first place! At first I thought the 16bit int could be the reason, but inserting a ConvertAudioToFloat() didn't make a difference.
Is this some Avisynth shortcoming? And if so, how did you even come up with (AudioRate()*1001+480)/960)?!
tebasuna51
17th February 2012, 19:15
Then the first one is probably called "upmix matrix"?
Both are "downmix matrix" -> the output have less channels than input.
The first one is a "not-normalized" matrix and the second one is a "normalized" matrix (the output can't have values greater than 1.0)
If you use float values, and after normalize, you can use both.
But the function must work also with integer values, then you need use the "normalized matrix" to avoid clip.
And if so, how did you even come up with (AudioRate()*1001+480)/960)?!
The SSRC function only support integer values, then the operations are truncatted to int values.
Like: 25/ (24000/1001) = 1001 * (25/24000)= 1001 * (1/960) = 1001/960
Is more exact let the division to last operation, (instead multiply the error by 25):
(AudioRate()*1001)/960
And the '+ 480' factor (480/960 = 0.5) is to round to the next integer
int(45983.4 +0.5) -> 45983
int(45983.6 +0.5) -> 45984
For instance:
(44100*1001/24000)*25 = (1839) * 25 = 45975
far of 45983.4375
(44100*1001+480)/960 = 45983
near to 45983.4375
CoRoNe
17th February 2012, 20:49
Ah, mathematics. Nice! I understand now.
I realized not only SSRC is integer only, but AudioRate() and AssumeSampleRate() as well and that's why ConvertAudioToFloat() wouldn't make a difference.
With 48000Hz is just so happens to be all integer...
AudioRate(48000*1001/24000=2002) --> AssumeSampleRate(2002*25=50050)
...unlike 44100, where the truncation already begins with AudioRate()...
AudioRate(44100*1001/24000=1839.3375) --> AssumeSampleRate(1839*25=45975)
While with (AudioRate()*1001+480)/960) the truncation is 1 step later...
AudioRate(48000*1001+480=48048480) --> AssumeSampleRate(48048480/960=50050.50) --> 50050
...and...
AudioRate(44100*1001+480=44144580) --> AssumeSampleRate(44144580/960=45983.9375) --> 45983
Ingenious, really! :p Thanks for all the info, tebasuna51! :goodpost:
kolak
17th February 2012, 22:07
Is it possible to add generic (numbered) files/channels naming in wavsplit:
audio_1
audio_2
audio_3
etc
instead of
audio_L
audio_R
audio_C
...
Thanks
tebasuna51
18th February 2012, 03:31
Is possible but I don't like the idea.
EDIT: This is a modified version:
kolak
18th February 2012, 13:53
:thanks::thanks:
Could wavsplit extract wav directly from AVI or do I have to always use BeHAppy for this?
tebasuna51
18th February 2012, 19:26
wavsplit can't extract audio from avi.
BeHappy can' extract wav from avi, but can decode any audio from avi using DirectShowSource/AviSource
kolak
18th February 2012, 19:47
wavsplit can't extract audio from avi.
BeHappy can' extract wav from avi, but can decode any audio from avi using DirectShowSource/AviSource
Yes- that's what I'm using now- directshow source as it's 8 channels 24bit wav- so mostly >4GB. Only this works.
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.