Install
dotnet add package R128Net
Use
This program feeds 20 seconds of a stereo 1 kHz sine at -23 dBFS to a meter in blocks of 100 ms, then reads the integrated loudness, the loudness range and the true peak. It prints -23.0 LUFS, 0.0 LU and -23.0 dBTP.
using R128Net;
const int SampleRate = 48000;
const int BlockFrames = SampleRate / 10;
using LoudnessMeter meter = new(channels: 2, SampleRate,
LoudnessModes.Integrated | LoudnessModes.LoudnessRange | LoudnessModes.TruePeak);
float[] block = new float[2 * BlockFrames];
for (int n = 0; n < 200; ++n)
{
for (int i = 0; i < BlockFrames; ++i)
{
float value = (float)(0.0708 * Math.Sin(2.0 * Math.PI * 1000.0 * ((n * BlockFrames) + i) / SampleRate));
block[2 * i] = value;
block[(2 * i) + 1] = value;
}
meter.AddFrames(block);
}
Console.WriteLine($"Integrated loudness: {meter.IntegratedLoudness:F1} LUFS");
Console.WriteLine($"Loudness range: {meter.LoudnessRange:F1} LU");
Console.WriteLine($"True peak: {20.0 * Math.Log10(meter.GetTruePeak(0)):F1} dBTP");
What it does
- Momentary, short-term and integrated loudness, as EBU R128 and ITU-R BS.1770 define them.
- Loudness range, as EBU Tech 3342 defines it.
- The relative threshold, and the loudness over any window up to a maximum you set.
- Sample peak and true peak.
- The histogram algorithm, and the aggregation of several meters into a single figure.
- Input as 16-bit integers, 32-bit integers, single precision and double precision.
Why R128Net
- Faster than the original C in every mode measured. The tables are in the performance section of the README.
- No managed allocation. The garbage collector never observes the measurement path.
- Verified against the original built with MSVC. In the test suite the loudness and the peaks match the original to the bit.
- .NET 10, tested on x64 and ARM64, Windows and Linux. Native AOT ready. No native library to ship.
Links
- README: requirements, API reference, limitations.
- NuGet package
- Releases
- libebur128, the original by Jan Kokemüller.