From 9cbb67acba1fe36ccc9e4435e8ecee9981591e43 Mon Sep 17 00:00:00 2001 From: Max Maisel Date: Fri, 27 Jul 2018 16:50:27 +0200 Subject: [PATCH] Fix too low loudness normalization levels. LUFS are defined as the power of the signal, not as the root mean square. Accidential use of the RMS caused incorrect normalization to only half of the LUFS value. --- src/effects/Normalize.cpp | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/effects/Normalize.cpp b/src/effects/Normalize.cpp index d1c4f0abd..ee2fcec33 100644 --- a/src/effects/Normalize.cpp +++ b/src/effects/Normalize.cpp @@ -236,14 +236,19 @@ bool EffectNormalize::Process() if(!track->GetLinked() || mStereoInd) { // mono or 'stereo tracks independently' if( (extent > 0) && mGain ) + { mMult = ratio / extent; + if(mUseLoudness) + { + // LUFS is defined as -0.691 dB + 10*log10(sum(channels)) + mMult /= 0.8529037031; + // LUFS are related to square values so the multiplier must be the root. + mMult = sqrt(ratio / extent); + } + } else mMult = 1.0; - if(mUseLoudness) - // LUFS is defined as -0.691 dB + 10*log10(sum(channels)) - extent *= 0.8529037031; - msg = topMsg + wxString::Format( _("Processing: %s"), trackName ); if(track->GetLinked() || prevTrack->GetLinked()) // only get here if there is a linked track but we are processing independently @@ -284,7 +289,12 @@ bool EffectNormalize::Process() extent = fmax(extent, extent2); if( (extent > 0) && mGain ) + { mMult = ratio / extent; // we need to use this for both linked tracks + if(mUseLoudness) + // LUFS are related to square values so the multiplier must be the root. + mMult = sqrt(mMult); + } else mMult = 1.0; track = (WaveTrack *) iter.Prev(); // go back to the first linked one @@ -422,7 +432,8 @@ bool EffectNormalize::AnalyseTrack(const WaveTrack * track, const wxString &msg, offset = 0.0; } - extent = sqrt(mSqSum / mCount.as_double()); + // EBU R128: z_i = mean square without root + extent = mSqSum / mCount.as_double(); } else {