Log in

View Full Version : 5.1 to 2.0 audio conversion with DRC


Floatingshed
7th May 2020, 09:27
I have been using this:

LoadPlugin("...AudioLimiter.dll")

A1=GetChannel( C, 1 ).amplify(1.2).wavgainLimiter(1.2)
A2=GetChannel( C, 2 ).amplify(1.2).wavgainLimiter(1.2)
A3=GetChannel( C, 3 ).wavgainLimiter(1.1)
A4=GetChannel( C, 4 )
A5=GetChannel( C, 5 )
A6=GetChannel( C, 6 )
A1=MixAudio( MixAudio( A1, A5, 0.2818, 0.1627), MixAudio( A3, A4, 0.3254, 0.2301 ) )
A2=MixAudio( MixAudio( A2, A6, 0.2818, 0.1627 ), MixAudio( A3, A4, 0.3254, 0.2301 ) )
A=MergeChannels( A1, A2 ).normalize(0.9).WavGainLimiter(1.3)
Return A

However as I have now moved to Avisynth+ 64bit and there doesn't seem to be a 64bit version of AudioLimiter.dll I am a bit stuck. Can anyone suggest an alternative please?

StainlessS
7th May 2020, 11:46
There seems to be no source for it. [EDIT Despite IanB making repeated requests for source back in 2006]

hello_hello
7th May 2020, 12:32
Does it have to be Avisynth? The Dynamic Audio Normalizer is quite good. It works by increasing the volume of the quiet parts. The portable version of foobar2000 I uploaded recently has conversion presets for downmxing and compressing with the Dynamic Audio Normalizer bundled with ffmpeg.

https://forum.doom9.org/showthread.php?p=1908807#post1908807

The downmixing is done with the Matrix Mixer DSP, which you can easily modify to downmix to your taste, and it's configured to reduce the over-all volume according to the number of channels in the source so there can't be any clipping when the channels are combined (that's what it's normalize option does). My presets don't include the LFE channel as it's only supposed to augment the low frequencies in the other channels, and excessive low frequencies can mess with the compression. FFmpeg compresses the downmixed audio with the Dynamic Audio Normaliser, and some of the encoder presets pipe the audio from ffmpeg to QAAC for encoding. There's a component included giving foobar2000 the ability to open Avisynth scripts and play/convert the audio.

ffmpeg and ffprobe aren't included in the zip file as they double it's size, but everything else is ready to go. There's some basic instructions in a text file you should read, but once it's working properly you can load the audio into a playlist, then right click and select "Convert/Downmix & Compression, Dynamic Audio Normaliser". The output for that conversion preset is AAC via QAAC. The conversion preset has QAAC configured for slightly lower VBR quality than the default (-V 64), but there's another QAAC encoder preset for the default quality (-V 91), or you can create your own.

If for some reason you don't like the compression you can modify the encoder command line to adjust it. The reason for compressing with ffmpepg rather the the CLI version of the Dynamic Audio Normalizer, is the latter doesn't support the fake wave file header most GUIs use to specify channel layout and sample rate etc for the encoder, so it's not very GUI friendly.

https://ffmpeg.org/ffmpeg-all.html#dynaudnorm

Some screenshots:

https://i.postimg.cc/hzy7FF50/1.jpg (https://postimg.cc/hzy7FF50)

https://i.postimg.cc/ZvWv47kz/2.jpg (https://postimg.cc/ZvWv47kz)

https://i.postimg.cc/KkvgscJz/3.jpg (https://postimg.cc/KkvgscJz)

The highlighted encoder preset above has the Dynamic Audio Normalizer configured for my preferred compression and encodes with QAAC's default VBR quality. It should compress a fair bit without any noticeable "volume pumping".

tebasuna51
7th May 2020, 18:39
However as I have now moved to Avisynth+ 64bit and there doesn't seem to be a 64bit version of AudioLimiter.dll I am a bit stuck. Can anyone suggest an alternative please?

You can have installed both Avisynth+ 64bit and Avisynth+ 32bit at same time.

How do you run that .avs?

tormento
7th May 2020, 20:01
I do use (example):
ffmpeg.exe -i [eng].dts -acodec ac3 -ab 640k -af dynaudnorm=f=2000:g=23:m=15 [eng].ac3
The values are fine tuned for movies but I found it's of for music too.

Floatingshed
7th May 2020, 21:25
You can have installed both Avisynth+ 64bit and Avisynth+ 32bit at same time.



All my filters are 64 bit, I have ditched 32 bit to enjoy far better memory handling (which is so much better).


Does it have to be Avisynth?


Preferably, I would like to avoid processing the sound manually, the now unusable script managed the audio automatically. Ideal!

StainlessS
7th May 2020, 21:49
Floatingshed,
Dont have such a closed mine, of course you can process audio in 32 bit, if only to output .WAV, [maybe via VirtualDub2 or something] then continue and use both together in MeGUi 64 or whatever.

Having both 32 and 64 bit is not a totally bad idea. [EDIT: at least as a stop gap measure]

tebasuna51
8th May 2020, 13:01
All my filters are 64 bit, I have ditched 32 bit to enjoy far better memory handling (which is so much better).

Of course, but you can use BeHappy to manage audio, like MeGUI but with many more options.

Work with AviSynth+ 32 bits but the final encoders can be 64 bits.

tebasuna51
8th May 2020, 15:50
@tormento
Your output is 5.1, even if you select -ac 2 to obtain 2.0 the downmix is not controlled.

@hello_hello
With your method I obtain:

FL' = 0.79*FL + 0.55*FC + 0.55*SL
FR' = 0.79*FR + 0.55*FC + 0.55*SR

With the Floatingshed avs (loaded in BeHappy) I obtain:

FL' = 0.92*FL + 0.97*FC + 0.87*LFE + 0.61*SL
FR' = 0.92*FR + 0.97*FC + 0.87*LFE + 0.61*SR

Of course is not the same, but there are also a wrong concept in your method.
Any dynaudnorm effect can't be applied after the downmix, because the low volume (most the time the dialogs) mixed with high volume (front channels) are masked, must be applied for each channel and after downmix.

hello_hello
8th May 2020, 16:50
Preferably, I would like to avoid processing the sound manually, the now unusable script managed the audio automatically. Ideal!

Don't you use something to encode it? You can downmix and compress while you convert with fb2k with a couple of mouse clicks once you've created a converter preset.

If you're interesting in comparing the DRC, have a listen to the attached samples. I was curious as to what the difference would be myself.

I used Trim() to splice two short sections from a movie together (the first mainly speech and the second loud gunshots), and used the different downmix/compression methods while converting to wave files, then I ran a ReplayGain scan on the wave files and converted to flac while adjusting them all to the same average volume to make it a fair comparison (the loudest average volume I could use without any of them having clipped peaks). The ReplayGain peak values saved to the files are the result of "true peak" scanning.

"Avisynth DRC.flac" - Downmixed with DRC using your script.

"DownMix Only Avisynth.flac" - Downmixed using the method from your script, minus the Amplify and WavgainLimiter stuff.
"DownMix Only Matrix Mixer.flac" - Downmixed using my settings for the Matrix Mixer without any compression.

"f=150 b=1.flac" - Downmixed & compressed with my usual settings for the DAN.
"f=2000 g=23 m=15 b=1.flac" - Downmixed & compressed with tormento's settings for the DAN.
(with the boundary option enabled to make it fairer).

A flac version of the source is included.

If DRC is the main object of the exercise, you're missing out. ;)

DRC Samples.zip (https://files.videohelp.com/u/210984/DRC%20Samples.zip) (42.9MB)

hello_hello
8th May 2020, 17:12
@hello_hello
With your method I obtain:

FL' = 0.79*FL + 0.55*FC + 0.55*SL
FR' = 0.79*FR + 0.55*FC + 0.55*SR

That's probably about right.
0.79 is -2.05dB
0.55 is -5.19db

I specified 0.707 for the centre and surround channels, which is 3.01dB less than the front stereo channels, so it's pretty close. The Matrix Mixer's normalise option will then reduce the gain for each channel by the same amount to prevent clipping. If you add the LFE channel to the downmix you'll find the volumes for the front, centre and surround channels will be slightly lower again. The volume at which you add the LFE channel would effect how much the overall volume is adjusted.

Of course is not the same, but there are also a wrong concept in your method.
Any dynaudnorm effect can't be applied after the downmix, because the low volume (most the time the dialogs) mixed with high volume (front channels) are masked, must be applied for each channel and after downmix.

There's no reason why you couldn't run the DAN over the 5.1ch audio, then downmix to stereo, but it'd make it a two step process and to be honest I'm not sure it's necessary, and the result would be similar unless channel coupling was disabled, but that'd amplify stuff you're not wanting to amplify too. Most of the time, audio goes from normal speech to loud music and action, and it's the difference between them you want to even out so you don't have to turn the volume down during car chases and turn it up again when people are talking normally. Most of the time when things get loud it'll be something like "a bunch of gunshots", "some speech", "an explosion", "gunshots", "people yelling" etc etc, and I have the DAN set to react pretty quickly. It increases the risk of "volume pumping", but it'll react fast enough to even that sort of thing out if need be.

Have a listen to the samples I uploaded and tell me what you think. Unfortunately there's no speech during the loud part at the end, but comparing the speech in the first part with the loud stuff is night and day without the DAN. In the middle section there's an acoustic guitar and if you listen for it I think it's volume changes a bit as the compression reacts to the stuff over the top (my DAN settings), but it doesn't sound unnatural to me, and at least you can hear it and the speech isn't quiet.

Edit A spanner in the works for the samples I uploaded will be the loud stuff at the end. There's lots of it in the centre channel too, and even if the loud stuff doesn't increase in volume when that channel is compressed, if centre channel volume is increased for downmixing, the loud stuff at the end is going to get louder. I'm not sure if there's an easy way to deal with that sort of thing, even if you compress the centre channel separately.

hello_hello
8th May 2020, 19:20
I've been listening to the two samples I uploaded that were downmixed with the script in the opening post, one without and one with the Amplify and WavgainLimiter stuff. If the latter has DRC compared to the first, I'm struggling to find it. In theory there's a difference, because after I adjusted them to the same volume using ReplayGain, the difference in the maximum peak is around 3.5dB. The downmix with DRC has the lower peak, so if ReplayGain is correct about the average volume, it has less dynamic range, but I'll confess I'm struggling to hear it.

tormento
9th May 2020, 09:47
Your output is 5.1, even if you select -ac 2 to obtain 2.0 the downmix is not controlled.
AFAIK ffdshow already applies correct parameters when downmixing.

Anyway, I suggest to encode to a minimum of 5.1 and let the player do the dirty job as, some day, you could buy a soundbar or a proper audio system.