Log in

View Full Version : Right way to convert AC3 5.1 to stereo WAV?


zee944
8th May 2013, 13:05
Is there a consensus on this one?
I know it wasn't obvious in the past and there was a lot of arguments about on with what weight the Center channels should be mixed into the Left and Right, also if the surround channels should be mixed with fronts 1:1 etc. I didn't find anything specific about it in the FAQ.

How could I do this the properly? What I need to convert to stereo now is an 5.1 audio track of a Hollywood movie. I want a stereo WAV in the end (for further work before encoding), not an AC3 file.

Thanks in advance.

tebasuna51
8th May 2013, 20:01
What is properly?

If we read AC3 documentation there are a field in each header than show the nominal (proper?) weight for mix Center channel:

5.4.2.4 cmixlev: Center Mix Level, 2 bits
When three front channels are in use, this 2-bit code, shown in Table 5.9, indicates the nominal down mix level of the center channel with respect to the left and right channels...

Table 5.9 Center Mix Level
cmixlev clev
------- ---------------
'00' 0.707 (-3.0 dB)
'01' 0.595 (-4.5 dB)
'10' 0.500 (-6.0 dB)
'11' reserved

This mix value is applied when you use some decoders than make the downmix.
For instance if you use NicAc3Source("some.ac3", Channels=2)

When the downmix is make out of the decoder (eac3to, BeHappy, ...) we always use the max value (-3.0 dB).

But some users (not all and not in all movies) have problems listen dialogs even with this max value.
For these users I recommend apply Dynamic Range Compression (if the ac3 have this data in the ac3 stream) with:
NicAc3Source("some.ac3", Channels=2, DRC=1)

zee944
8th May 2013, 20:38
On properly I mean... with more or less the right weights. :) I may be overcomplicating it a bit, but there were different formulas on different forums floating around how to downmix an 5.1 to stereo.

So do you say if I open the 5.1 audio through AviSynth with "NicAc3Source("some.ac3", Channels=2)", and in VirtualDub I save the WAV from the File menu, is a good method? I don't have to adjust anything further?

tebasuna51
9th May 2013, 00:23
Or you can use eac3to, more easy and using max mix Center channel:

eac3to some.ac3 output.wav -downStereo -normalize

Only need AviSynth to apply DRC.
If you have AviSynth installed and NicAudio.dll in AviSynth plugins folder you can load in VirtualDub this avs:

NicAc3Source("some.ac3", Channels=2, DRC=1)
AudioDubEx(BlankClip(length=Int(25*AudioLengthF(last)/Audiorate(last)), width=32, height=32, pixel_type="RGB24", fps=25), last) #1
Normalize() #2
ConvertAudioto24bit() #3

1) VirtualDub crash if don't found video.
2) Recommended to obtain max volume
3) By default VirtualDub output 16 bit wav, maybe you want more precission.

Or you can use BeHappy:
[1] Source
Select NicAc3Source and configure it [...] like (Down2, DRC).
Select the ac3 file.

[3] DSP
Check and Configure Normalize.
Check and configure Convert Sample To (by default the output is 32 bit float)

[4] Destination
Select Wav Writer and the desired name.

zee944
9th May 2013, 20:18
Or you can use eac3to, more easy and using max mix Center channel

On 'max', you mean the -3.0 dB mixing, is that right?

Are there quality (accuracy) difference between these methods?

tebasuna51
9th May 2013, 21:44
Yes, -3.0 dB.

AviSynth work with 32 bit float, enough for AC3 audio (equivalent to 20 bit int accuracy), eac3to work with 64 bit float.

zee944
9th May 2013, 22:00
AviSynth work with 32 bit float, enough for AC3 audio (equivalent to 20 bit int accuracy), eac3to work with 64 bit float.

Then eac3to is the way to go in every sense if I don't want dynamic range compression.

Does it make sense to use 32 bit WAVs as output format, or 24 bit is more than enough and impossible to make a distinction between them?

IanB
9th May 2013, 23:04
... with 32 bit float, enough for AC3 audio (equivalent to 20 bit int accuracy), ...32bit IEEE floats have 24 bit mantissa precision.

tebasuna51
10th May 2013, 02:01
32bit IEEE floats have 24 bit mantissa precision.

Yes is correct, for that is enough to operate with AC3 audio samples with a precision equivalent to 20 bit int .

Perhaps I have not expressed well.

tebasuna51
10th May 2013, 02:10
Does it make sense to use 32 bit WAVs as output format, or 24 bit is more than enough and impossible to make a distinction between them?

The average human ear can distinguise until 20 bit precision.

To make the downmix is good use high precision, but like final output is enough 24 bits.

IanB
10th May 2013, 03:47
... with 32 bit float, enough for AC3 audio (equivalent to 20 bit int accuracy), ...32bit IEEE floats have 24 bit mantissa precision.Yes is correct, for that is enough to operate with AC3 audio samples with a precision equivalent to 20 bit int .I assumed the first post was a typo, but you are serious, and you are very rarely wrong so now I am interested in learning why.

I have always assumed a 32bit IEEE float could losslessly manipulate 24 bit integer data because all 16777216 integer states can be exactly represented. I appreciate that multiplying two 24 bit numbers gives a 48 bit result, so to achieve a similarly intermediate precision one would need to step up to using a 64 bit Double and that is a fair comparison because the integer path has stepped up to 48bits. So I still do not see where we loose the 4 bits. :confused:

zee944
10th May 2013, 09:54
To make the downmix is good use high precision, but like final output is enough 24 bits.

Okay. Thank you for the detailed responses to my questions. It was very helpful.

Ghitulescu
10th May 2013, 10:19
There is no proper way to downmix an originally created multitrack audio. The way a TV downmixes the 5.1 is IIRC to keep the L and R channels as they are, then to add the surround ones and finally to distribute the LFE to both.
The proper way to downmix a multitrack audio created form an original 2.0 track is the reconstruction of the original channels.

zee944
10th May 2013, 11:02
There is no proper way to downmix an originally created multitrack audio. The way a TV downmixes the 5.1 is IIRC to keep the L and R channels as they are, then to add the surround ones and finally to distribute the LFE to both.
The proper way to downmix a multitrack audio created form an original 2.0 track is the reconstruction of the original channels.

There has to be reasonable, approximate methods.

How do you know that eac3to (or the other two) doesn't do the way you're talking about? BTW, you haven't specified the "right" mixing weights.

And how can something "keep the L and R channels as they are", when there are all the other channels that will be mixed into them?

tebasuna51
10th May 2013, 14:21
I assumed the first post was a typo, but you are serious, and you are very rarely wrong so now I am interested in learning why.

I have always assumed a 32bit IEEE float could losslessly manipulate 24 bit integer data because all 16777216 integer states can be exactly represented. I appreciate that multiplying two 24 bit numbers gives a 48 bit result, so to achieve a similarly intermediate precision one would need to step up to using a 64 bit Double and that is a fair comparison because the integer path has stepped up to 48bits. So I still do not see where we loose the 4 bits. :confused:

Maybe I'm wrong but I try to explain.

When a CBR encoder like AC3 (also standard DTS is similar) make a encode to 448 Kb/s over a audio with samplerate 48000 (for instance) work like this:

Take 1536 samples (32 ms) from the uncompressed audio data in time domain and convert them to frequency domain (Fourier transform) and finish with a amount of frequencies with coeficients. These data must be stored in a AC3 frame of 1792 bytes (448 Kb/s) when don't fit first reject all frequencies over 20300 KHz (Band filter) and after reject the less significant coeficients until fit in the frame size.

I'm not sure what mean when Dolby say: the data stored have a equivalent precision to 20 bit int in time domain.
Because we can't recover the exact samples in time domain even if source was 16 bit int.

The decoder (NicAudio) recover the samples like 32 bits float but the less significant bits are very far of exact original values.
We can work with 32 bit float because is the best aproach we can know over the original samples, but without worry about precision in operations.

BTW the downmix process only multiply audio samples with fix mix-levels coeficients and is not very important any rounding error here. Between audio data we only need add operation.

To finish, the difference between use 64 bit float or 32 bit float is always over less significants bits, always innacurated with samples from lossy codecs.

There is no proper way to downmix an originally created multitrack audio.
Of course, we can offer only a aceptable aproach.

The way a TV downmixes the 5.1 is IIRC to keep the L and R channels as they are, then to add the surround ones and finally to distribute the LFE to both.

I think the main problem is how mix the Center channel to listen the dialogs with high volume music/effects.

If DRC is needed must be applied over the 5.1 before downmix. A typical AC3 audio track can have music/effects peaks at 0 dB and dialogs at -27 dB, the DRC (film standard) reduce the volume peaks of music/effects to -16 dB and preserve the dialog volume.
After that we can mix the Center channel.
If we mix before the Center channel DRC is useless.

About surround channels there are some options, but for most tracks is not so important than Center mix:

Plain stereo. Mix SL over FL and SR over FR only, recommended if you never want play it in a 5.1 system. We can also use different mix levels.

Dolby Pro Logic. We can recover a Back Channel with the appropriate mix levels.

Dolby Pro Logic. We can recover Surround Channels with the appropriate mix levels. Recommended if you want play it in a 5.1 system in the future.

About LFE. Dolby dont' recommend use the LFE channel in a downmix.

The proper way to downmix a multitrack audio created form an original 2.0 track is the reconstruction of the original channels.
Yes, but we don't know the method used to create the multichannel.
If we plain downmix a multichannel track is always better check if exist a 2.0 version, maybe the original or at least with a proper downmix.

IanB
11th May 2013, 00:22
I'm not sure what mean when Dolby say: the data stored have a equivalent precision to 20 bit int in time domain. Because we can't recover the exact samples in time domain even if source was 16 bit int.
I think this means that the precision used in the frequency domain is sufficient to accurately represent 20 bit precision in the time domain. This is sort of akin to needing 10bits in YUV colour space to accurately represent 8 bits in RGB colour space. By inference the frequency domain calculations must require more that 24 bits of precision.

I can easily see that doing the Inverse Fourier Transform computations with just 32bit IEEE floats may easily have insufficient intermediate precision to produce an accurate 20 bit representation in the time domain. But within time domain alone calculations, 32bit IEEE floats have enough precision to be lossless with 24bit integers values.

zee944
24th May 2013, 10:05
I've decoded the same 5.1 audio of a movie as stereo WAV with both EAC3TO and NicAudio (with no DRC), checked with GoldWave and they are different.

EAC3TO:

eac3to movie.ac3 output.wav -downStereo -normalize

average L: -31.79
average R: -31.06
peak L: -1.14
peak R: -0.09

NicAudio:

LoadPlugin("NicAudio[2.0.4].dll")
NicAc3Source("movie.ac3", Channels=2, DRC=0)
AudioDubEx(BlankClip(length=Int(25*AudioLengthF(last)/Audiorate(last)), width=32, height=32, pixel_type="RGB24", fps=25), last)
Normalize()
ConvertAudioto24bit()

average L: -31.31
average R: -30.67
peak L: -0.26
peak R: -0.00

The average difference between Left and Right would be acceptable, but the peak results shows that something is truly wrong. More than 1 dB difference with eac3to, and only 0.26 dB difference in the other.

Shouldn't the results be the nearly same?

tebasuna51
24th May 2013, 15:21
1) First the decoders used are different, libav-eac3to and liba52-NicAc3Source, then there are always light differences.

2) The downmix than make NicAc3Source is Dolby ProLogic (can recover 4 channels), with eac3to you can obtain pure stereo (-downStereo) or Dolby ProLogic II (-DownDpl, can recover 5 channels).

To obtain the equivalent downmix than -downStereo with NicAc3Source you can use BeHappy with the DSP Downmix-Stereo or this avs:
LoadPlugin("NicAudio[2.0.4].dll")
a=NicAc3Source("movie.ac3")
flr = GetChannel(a, 1, 2)
fcc = GetChannel(a, 3)
lfe = GetChannel(a, 4)
lfc = MixAudio(fcc, lfe, 0.2071, 0.2071)
mix = MergeChannels(lfc, lfc)
lrc = MixAudio(flr, mix, 0.2929, 1.0)
blr = GetChannel(a, 5, 6)
MixAudio(lrc, blr, 1.0, 0.2929)
Normalize()
ConvertAudioto24bit()
AudioDubEx(BlankClip(length=Int(25*AudioLengthF(last)/Audiorate(last)), width=32, height=32, pixel_type="RGB24", fps=25), last)

zee944
24th May 2013, 17:01
2) The downmix than make NicAc3Source is Dolby ProLogic (can recover 4 channels), with eac3to you can obtain pure stereo (-downStereo) or Dolby ProLogic II (-DownDpl, can recover 5 channels).

1. I'm confused. Which result was closer to a true stereo mix then?
Are you saying that the script I used for NicAudio created a Dolby ProLogic track? So the eac3to version was the right one?

2. By the way, isn't it suspicious that the right channel is notably louder than the left? It's a 2 hour movie with mostly dialogues and very little action in it, I can't recall any longer off-balance scenes that could have threw the average off balance by ~0.7 dB.

tebasuna51
24th May 2013, 21:51
1. I'm confused. Which result was closer to a true stereo mix then?
eac3to -downstereo or the .avs I put.

Are you saying that the script I used for NicAudio created a Dolby ProLogic track?
Yes, we can recover FL,FR,FC,BC.

2. By the way, isn't it suspicious that the right channel is notably louder than the left?
Notably? Not at all, 0.7 dB is not a big difference.

zee944
25th May 2013, 09:14
eac3to -downstereo or the .avs I put.
You mean the more recent .avs with 'lfr', 'fcc' etc. variables, right?

This script includes the LFE channel into the mix, while eac3to doesn't (if I'm right). Which one is better?

If DRC is needed must be applied over the 5.1 before downmix. A typical AC3 audio track can have music/effects peaks at 0 dB and dialogs at -27 dB, the DRC (film standard) reduce the volume peaks of music/effects to -16 dB and preserve the dialog volume.

How do I know if DRC is needed? Is there a scientific method to find it out (a flag in the AC3, on the DVD or something else), or only by ear? How does a TV or DVD player decide how to downmix it on a stereo system?

tebasuna51
25th May 2013, 18:15
This script includes the LFE channel into the mix, while eac3to doesn't (if I'm right). Which one is better?
You are right, my mistake. The recommended mix is without LFE:

LoadPlugin("NicAudio[2.0.4].dll")
a=NicAc3Source("movie.ac3")
flr = GetChannel(a, 1, 2)
fcc = GetChannel(a, 3, 3)
lrc = MixAudio(flr, fcc, 0.3694, 0.2612)
blr = GetChannel(a, 5, 6)
MixAudio(lrc, blr, 1.0, 0.3694)
Normalize()
ConvertAudioto24bit()
AudioDubEx(BlankClip(length=Int(25*AudioLengthF(last)/Audiorate(last)), width=32, height=32, pixel_type="RGB24", fps=25), last)

How do I know if DRC is needed? Is there a scientific method to find it out (a flag in the AC3, on the DVD or something else), or only by ear?
There aren't flags.
You can analyze the audio. If Peak values are near 0 dB and RMS values around -30 dB the audio have a high dynamic range and is recommended use DRC before downmix.

How does a TV or DVD player decide how to downmix it on a stereo system?
I think the default is apply DRC before downmix.

zee944
25th May 2013, 19:38
You can analyze the audio. If Peak values are near 0 dB and RMS values around -30 dB the audio have a high dynamic range and is recommended use DRC before downmix.

What tool should I use to check the RMS values?

And where would you draw the line? For instance, if RMS is closer to zero than -20 dB, then you should never apply DRC, and if -30 dB or even lower, then you better do it...?

I think the default is apply DRC before downmix.
How should I do it? I've checked NicAudio documentation, but it seems DRC can only be applied when you're opening the AC3 file (the same way you did it earlier). Will that be OK?

a=NicAc3Source("movie.ac3", Channels=6, DRC=1)

tebasuna51
26th May 2013, 02:04
What tool should I use to check the RMS values?
Load this .avs in VirtualDub, for instance, and click over 'Analyze Sound'

LoadPlugin("NicAudio[2.0.4].dll")
LoadPlugin("SoundOut.dll")
NicAc3Source("movie.ac3")
SoundOut()

And where would you draw the line?
I never downmix 5.1 to 2.0, I listen always 5.1.
Each one must draw your line.

but it seems DRC can only be applied when you're opening the AC3 file ...
Yes, NicAc3Source("movie.ac3", DRC=1) force the decoder to apply the DRC values, if exist in the ac3 stream.