From 6366e54a438571f2fef6515f1897caca6a6dab25 Mon Sep 17 00:00:00 2001 From: yellowsink Date: Sat, 4 Nov 2023 22:07:16 +0000 Subject: [PATCH] [server] lets try a simpler and hopefully less buggy Normalize() impl --- UwuRadio.Server/Constants.cs | 2 +- UwuRadio.Server/DSP.cs | 5 ++++- UwuRadio.Server/constants.debug.json | 2 +- UwuRadio.Server/constants.json | 2 +- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/UwuRadio.Server/Constants.cs b/UwuRadio.Server/Constants.cs index cab80ff..86a65ae 100644 --- a/UwuRadio.Server/Constants.cs +++ b/UwuRadio.Server/Constants.cs @@ -65,5 +65,5 @@ public static Constants /// /// The target Integrated LUFS /// - public string AudioNormIntegrated { get; set; } = null!; + public double AudioNormIntegrated { get; set; } } diff --git a/UwuRadio.Server/DSP.cs b/UwuRadio.Server/DSP.cs index 41ebf80..0130a6a 100644 --- a/UwuRadio.Server/DSP.cs +++ b/UwuRadio.Server/DSP.cs @@ -51,8 +51,11 @@ public static async Task MeasureLoudness(string path) public static async Task Normalize(string inPath, string outPath, LoudnessMeasurement measurement) { + var lufsLoudnessChange = Constants.C.AudioNormIntegrated - measurement.IntegratedLoudness; + var clampedLoudnessChange = Math.Min(lufsLoudnessChange, -measurement.TruePeak); + var args = new List { "-nostdin", "-i", inPath, "-filter:a", - $"loudnorm=measured_i={measurement.IntegratedLoudness}:measured_thresh={measurement.IntegratedThreshold}:measured_lra={measurement.LoudnessRange}:measured_tp={measurement.TruePeak}:i={Constants.C.AudioNormIntegrated}", + $"volume={clampedLoudnessChange}dB", "-f", Constants.C.AudioFormat }; diff --git a/UwuRadio.Server/constants.debug.json b/UwuRadio.Server/constants.debug.json index 08ddb9c..427b0c9 100644 --- a/UwuRadio.Server/constants.debug.json +++ b/UwuRadio.Server/constants.debug.json @@ -7,5 +7,5 @@ "IngestFolder": "../ingest", "AudioFormat": "mp3", "AudioQScale": "6", - "AudioNormIntegrated": "-16" + "AudioNormIntegrated": -16 } diff --git a/UwuRadio.Server/constants.json b/UwuRadio.Server/constants.json index 30dd069..133621c 100644 --- a/UwuRadio.Server/constants.json +++ b/UwuRadio.Server/constants.json @@ -7,5 +7,5 @@ "IngestFolder": "ingest", "AudioFormat": "mp3", "AudioQScale": "6", - "AudioNormIntegrated": "-16" + "AudioNormIntegrated": -16 }