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 9th June 2017, 21:08   #21  |  Link
tebasuna51
Moderator
 
tebasuna51's Avatar
 
Join Date: Feb 2005
Location: Spain
Posts: 6,890
My fault. Yes MixAudio is limited to 2 clips.

Then we need two pass:

c = MixAudio(left,c, 0.8, 1.0)
MixAudio(c, right, 1.0, 0.8).Normalize()
__________________
BeHappy, AviSynth audio transcoder.
tebasuna51 is offline   Reply With Quote
Old 11th June 2017, 14:40   #22  |  Link
Richard1485
Guest
 
Posts: n/a
That works. Thanks! The downmix sounds nice.

Quote:
Originally Posted by hello_hello View Post
Mind you I prefer using a GUI...
...Messing around with individual mono wave files or intermediate files seems too hard when you can just open a file, right click and convert, and let the GUI take care of the channel mask stuff.
I dislike GUIs and am happier writing a script (or quickly adapting an existing one, as is usually the case). Most of the time, I decode my audio with eac3to and can pick my output format, so only rarely do I have cause to create individual WAVs. I appreciate your writing a downmix function though. I'm sure it will come in handy at some stage. :-)
  Reply With Quote
Old 2nd August 2018, 21:06   #23  |  Link
Nikos
Registered User
 
Join Date: Jun 2002
Location: Greece
Posts: 242
After reading carefully the previous posts, i decided to make my own script to convert from 5.1 channels to plain stereo (without LFE) and i want your opinion.

fl = WavSource("L.wav").ConvertAudioToFloat()
fr = WavSource("R.wav").ConvertAudioToFloat()
c = WavSource("C.wav").ConvertAudioToFloat()
sl = WavSource("SL.wav").ConvertAudioToFloat()
sr = WavSource("SR.wav").ConvertAudioToFloat()

# For sg, i consider the values between 0.707 and 1.0 reasonable.
left = MixAudio(fl, sl, 1.0, sg).SoftClipperFromAudX(0.0) # reduce volume only if clip is detected
right = MixAudio(fr, sr, 1.0, sg).SoftClipperFromAudX(0.0) # reduce volume only if clip is detected

# For cg, i think the maximum value should be 0.707, because the acustic power is the square of the amplitude.
--> Edit: the minimum value should be 0.707. <--
(0.707 x 0.707) + (0.707 x 0.707) = 0.5 + 0.5 = 1.
leftc = MixAudio(left, c, 1.0, cg)
rightc = MixAudio(right, c, 1.0, cg)

# Stereo (Maybe we need attenuate or amplify)
mix = MergeChannels(leftc, rightc)

# Check for overflows and RMS values, with SoundOut plugin
# SoundOut(mix)

# Final stage
Normalize(mix) # 0dB
# or
# Normalize(mix, 0.89125) # -1dB
# or
# AmplifydB(mix, ...)

__________________
Greece PAL User...

Last edited by Nikos; 3rd August 2018 at 13:35. Reason: Correction to the cg value
Nikos is offline   Reply With Quote
Old 2nd August 2018, 23:48   #24  |  Link
FranceBB
Broadcast Encoder
 
FranceBB's Avatar
 
Join Date: Nov 2013
Location: Royal Borough of Kensington & Chelsea, UK
Posts: 2,883
@Nikos... There are many ways to make a stereo downmix out of a 5.1 surround, many people generally use Dolby Pro Logic II, like so:

Quote:
function Dmix5Dpl2(clip a) # 5 Channels L,R,C,SL,SR -> dpl II
{
flr = GetChannel(a, 1, 2)
fcc = GetChannel(a, 3, 3)
lrc = MixAudio(flr, fcc, 0.3254, 0.2301)
bl = GetChannel(a, 4)
br = GetChannel(a, 5)
sl = MixAudio(bl, br, 0.2818, 0.1627)
sr = MixAudio(bl, br, -0.1627, -0.2818)
blr = MergeChannels(sl, sr)
return MixAudio(lrc, blr, 1.0, 1.0)
}
FranceBB is online now   Reply With Quote
Old 2nd August 2018, 23:53   #25  |  Link
tebasuna51
Moderator
 
tebasuna51's Avatar
 
Join Date: Feb 2005
Location: Spain
Posts: 6,890
The standard Downmix uses sg = 1 and cg = 0.707.
In my opinion sg can be lower, but cg can't be lower to preserve dialog volume.

The big difference in your method is include the SoftClipperFromAudX() in the first mix.
I'm not sure about that, I use SoftClipperFromAudX() in 7.1 -> 5.1 mixing back and side channels not so important than front channels.

But if work for you...
__________________
BeHappy, AviSynth audio transcoder.
tebasuna51 is offline   Reply With Quote
Old 3rd August 2018, 02:07   #26  |  Link
Nikos
Registered User
 
Join Date: Jun 2002
Location: Greece
Posts: 242
Thank you guys for the answers.
I understand that sg can be lower, I think that sg = 0.707 is reasonable and we are in line with the ITU-R BS.775-3 recommendation.

I encode old movies with 5.1 audio and the surround channels are mostly empty.
The SoftClipperFromAudX(), it's not critical and work for me
I'm more interested in the center channel.

In a test, Ι did in "The Good, the Bad and the Ugly" with the above script (sg=1.0 and cg=0.707), Ι had to add AmplifydB(mix,-3.61) to avoid overflows, while with sg=0.707 and cg=0.707, Ι had to add AmplifydB(mix,-3.23).

I need a clarification about cg:
With cg=0.707 we have all the acoustic power of the center channel.
Why we have to increase the cg beyond 0.707? (Unless it is a badly made film)
Which value range is acceptable?
__________________
Greece PAL User...

Last edited by Nikos; 3rd August 2018 at 02:15.
Nikos is offline   Reply With Quote
Old 3rd August 2018, 08:47   #27  |  Link
tebasuna51
Moderator
 
tebasuna51's Avatar
 
Join Date: Feb 2005
Location: Spain
Posts: 6,890
Quote:
Originally Posted by Nikos View Post
I encode old movies with 5.1 audio and the surround channels are mostly empty.
The SoftClipperFromAudX(), it's not critical and work for me
When original source is stereo (or even mono in very old movies) the 5.1 provided was created with artificial (or empty) surround channels derived from front channels.
To downconvert to stereo is safe (we don't lose audio info) ignore the surround channels and use only the front channels (your second mix).

Quote:
Why we have to increase the cg beyond 0.707? (Unless it is a badly made film)
Which value range is acceptable?
Like you say the 0.707 value is the recommended unless you experiment low dialog volume.
__________________
BeHappy, AviSynth audio transcoder.
tebasuna51 is offline   Reply With Quote
Old 3rd August 2018, 13:11   #28  |  Link
Nikos
Registered User
 
Join Date: Jun 2002
Location: Greece
Posts: 242
@tebasuna51 thank you for the clarifications.
You are right in everything
The cg value can't be lower than 0.707 to preserve dialog volume.

Another question:
Is there any reason to add to the script:
Global OPT_UseWaveExtensible = true
and or
Global OPT_dwChannelMask = ("0x00003") # for stereo
__________________
Greece PAL User...
Nikos is offline   Reply With Quote
Old 3rd August 2018, 21:03   #29  |  Link
tebasuna51
Moderator
 
tebasuna51's Avatar
 
Join Date: Feb 2005
Location: Spain
Posts: 6,890
I don't know any encoder, or soft than accept avs input, than need WaveFormatExtensible headers for stereo wav's.
__________________
BeHappy, AviSynth audio transcoder.
tebasuna51 is offline   Reply With Quote
Old 4th August 2018, 13:02   #30  |  Link
Nikos
Registered User
 
Join Date: Jun 2002
Location: Greece
Posts: 242
After readind this page about decibel, Ι have a technical question:
Does the AmplifydB(sound, -3) line in Avisynth script, reduce the amplitude or acoustic power of the sound in half?
__________________
Greece PAL User...
Nikos is offline   Reply With Quote
Old 4th August 2018, 18:15   #31  |  Link
tebasuna51
Moderator
 
tebasuna51's Avatar
 
Join Date: Feb 2005
Location: Spain
Posts: 6,890
Yes, in amplitude 0.707 and in acustic power 0.5 (half).
Like you say before: ..." 0.707, because the acustic power is the square of the amplitude."
__________________
BeHappy, AviSynth audio transcoder.
tebasuna51 is offline   Reply With Quote
Old 4th August 2018, 19:43   #32  |  Link
Nikos
Registered User
 
Join Date: Jun 2002
Location: Greece
Posts: 242
Thank you very much for the answers you give me.
But... new day, new idea...
For old movies where the back channels are mostly empty, I can just encode the three front audio channels and during playback I can adjust the level of the dialogs with lav filter or ffdshow.

For example:
global OPT_dwChannelMask = ("0x00007")
audio = WavSource("5.1.wav")
GetChannels(audio, 1, 2, 3)

What is your opinion?

I did a test and in the resulting .wav file, the MediaInfo reports 3 channels but not Channel positions Front: L C R.

But in the resulting .m4a file from BeHappy, the MediaInfo reports 3 channels and Channel positions Front: L C R.

Edit:
With the help of the ChMask=7 in BeHappy, the 3 channels .wav have Channel positions Front: L C R.
__________________
Greece PAL User...

Last edited by Nikos; 5th August 2018 at 15:19.
Nikos is offline   Reply With Quote
Old 5th August 2018, 20:38   #33  |  Link
tebasuna51
Moderator
 
tebasuna51's Avatar
 
Join Date: Feb 2005
Location: Spain
Posts: 6,890
Quote:
Originally Posted by Nikos View Post
What is your opinion?
It's ok if you want preserve 3 channels, but some audio systems can have problems with multichannel.

Quote:
I did a test and in the resulting .wav file, the MediaInfo reports 3 channels but not Channel positions Front: L C R.
What soft you use to write a wav with this .avs?

BeHappy have a special AvisynthWrapper.dll to write the wav header WAVE_FORMAT_EXTENSIBLE with the selected chMask.
__________________
BeHappy, AviSynth audio transcoder.
tebasuna51 is offline   Reply With Quote
Old 5th August 2018, 22:26   #34  |  Link
Nikos
Registered User
 
Join Date: Jun 2002
Location: Greece
Posts: 242
I used the BeHappy.

Without ChMask=7, the resulting .wav file, reports 3 channels but not Channel positions Front: L C R.

With ChMask=7, the resulting .wav file, reports 3 channels and Channel positions Front: L C R.

Is there a manual way, to write the wav header WAVE_FORMAT_EXTENSIBLE, with the help of AvisynthWrapper.dll?
I can not find information about using it within an .avs script.
Ιt's part of ΒeΗappy source code?

I know that I can add the header, with the help of wavfix.

Today I did a test:
1. I converted a 5.1 DTS Master Audio sound, from an old movie to
3.0 (Front) .wav, 5.0 (Front+Back) .wav and 5.1 (Front+Back+LFE) .wav.

2. I coded the above three .wav files, with Nero AAC (-lc -q 0.60).

3. The results:
3.0 .acc --> 360 kb/s # normal
5.0 .aac --> 552 kp/s # normal
5.1 .aac --> 553 kp/s # ?

It seems strange to me the last result, I was expecting more than 553 kp/s.

I coded the LFE channel alone and the the resulting .aac have 10 kb/s!!!

Thank you for your support for so many years
__________________
Greece PAL User...

Last edited by Nikos; 6th August 2018 at 00:26.
Nikos is offline   Reply With Quote
Old 6th August 2018, 10:16   #35  |  Link
tebasuna51
Moderator
 
tebasuna51's Avatar
 
Join Date: Feb 2005
Location: Spain
Posts: 6,890
The ChMask is the most important field than add the WAVE_FORMAT_EXTENSIBLE header.
In BeHappy the header WAVE_FORMAT_EXTENSIBLE is used when the ChMask (in Tweak section) is activated.
And yes is part of BeHappy code.
If ChMask is let to 0 value a default is used for number of channels (like wavfix):

Code:
Chan.  Mask hex-dec  MS channels ordered      Description
-----  ------------  -----------------------  -----------------------
  1    0x0004     4  FC                       Mono            1/0.0
  2    0x0003     3  FL FR                    Stereo          2/0.0
  3    0x0007     7  FL FR FC                 Stereo + Center 3/0.0
  4    0x0033    51  FL FR BL BR              Quadro          2/2.0
  5    0x0037    55  FL FR FC BL BR           Dpl II          3/2.0
  6    0x003F    63  FL FR FC LF BL BR        Standard 5.1    3/2.1
  7    0x013F   319  FL FR FC LF BL BR BC     With Back Cent. 3/3.1
  8    0x063F  1599  FL FR FC LF BL BR SL SR  Standard 7.1    3/2/2.1
The channel order in a wav file for 3.0 is FL FR FC (not L C R)

The LFE (Low Frequency Effects) have only very low frequencies (filtered by DTS Master Audio) and most the time is empty in old movie sound tracks.
A VBR (Variable BitRate) encode (like Nero -q 0.60) need only a very low bitrate to add that channel.
Big bitrate is only needed for high frequencies.
__________________
BeHappy, AviSynth audio transcoder.
tebasuna51 is offline   Reply With Quote
Old 7th August 2018, 00:40   #36  |  Link
Nikos
Registered User
 
Join Date: Jun 2002
Location: Greece
Posts: 242
I understood well about the header and ChMask field in BeHappy.
I think there should be a reference about the ChMask in the help files.

Thanks again.
__________________
Greece PAL User...
Nikos is offline   Reply With Quote
Old 18th August 2018, 13:10   #37  |  Link
tebasuna51
Moderator
 
tebasuna51's Avatar
 
Join Date: Feb 2005
Location: Spain
Posts: 6,890
The ChMask is a problem for Avisynth, like I say to IanB (Avisynth 2.6 developer) long time ago, and to Avs+ developers recently, the ChMask must be a audio property replacing NumChannels (NumChannels can be obtained from ChMask only adding the bits).

The Global variables:

global OPT_UseWaveExtensible = true
global OPT_dwChannelMask = $7

are ignored or rejected (Wavi), and I don't know any soft than use them.

The ChMask by default for 3 channels audio is 3.0 ($7 or FL FR FC) for Wavi, avs2pipemod or BeHappy, but for ffmpeg is 2.1 ($11 or FL FR LFE), you can't create a AC3 3.0 directly with the .avs and ffmpeg:
Quote:
Guessed Channel Layout for Input Stream #0.0 : 2.1
All work for standard 2.0 or 5.1 because are defaults for all soft.
But if you have a not standard ChMask the Global variables are useless, and you need BeHappy or Wavi to specify the correct ChMask manually.
__________________
BeHappy, AviSynth audio transcoder.

Last edited by tebasuna51; 18th August 2018 at 13:17. Reason: add info
tebasuna51 is offline   Reply With Quote
Reply

Tags
configuration, dts-hd ma, merge channels, truehd

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 00:09.


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