LoudnessMeter
Integrated loudness, to ITU-R BS.1770-4, which is what EBU R128 and ReplayGain 2.0 both measure.
Loudness is not amplitude. A bass-heavy track and a bright one at the same peak level sound nothing alike, and the whole point of this standard is a number that agrees with what a listener would say. It gets there in three steps: filter each channel the way a head and torso colour sound, take the mean square over overlapping 400 ms blocks, and then throw away the blocks that are too quiet to count.
That last step is why a simple average is not good enough. A film with long silences would measure far quieter than it sounds, so the standard gates twice: absolutely, dropping anything below -70 LUFS, and then relatively, dropping anything more than 10 LU below the mean of what survived the first gate. What is left is the loudness of the parts anyone was listening to.
Feed interleaved float samples with feed and read result once at the end. The meter holds one block of history and nothing else, so a long file costs no more memory than a short one.
Channel weighting follows the standard, ITU-R BS.1770-4 Annex 1: the front channels count once, every back and side channel counts 1.41 times because sound arriving from behind is heard as louder than the same sound in front, and the LFE is not counted at all. FFmpeg's ebur128 filter weights the same speakers the same way. Each channel's speaker comes from the layout mask when the source declares one, and from the conventional layout for the channel count otherwise: 3 is 2.1, 4 is quad, 5 is 5.0, 6 is 5.1 with side surrounds, 7 is 6.1 and 8 is 7.1.
Parameters
the native-order layout mask of the source, or null when it declared none. A mask whose speaker count differs from channels is ignored.