From 89926519f95afaf88b953d117668ebc3cc944744 Mon Sep 17 00:00:00 2001 From: hwsmm Date: Tue, 14 May 2024 02:11:17 +0900 Subject: [PATCH] Fix variable hiding and throw instead of log in TrackLoudness --- osu.Framework/Audio/Track/TrackLoudness.cs | 28 +++++++++++----------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/osu.Framework/Audio/Track/TrackLoudness.cs b/osu.Framework/Audio/Track/TrackLoudness.cs index 15f84b5c5be..01ecb1c0c0e 100644 --- a/osu.Framework/Audio/Track/TrackLoudness.cs +++ b/osu.Framework/Audio/Track/TrackLoudness.cs @@ -46,7 +46,7 @@ public TrackLoudness(Stream? data) if (Bass.CurrentDevice < 0) { - Logger.Log("Failed to measure loudness as no bass device is available."); + Logger.Log("Failed to measure loudness as no bass device is available.", level: LogLevel.Error); return; } @@ -56,7 +56,7 @@ public TrackLoudness(Stream? data) if (decodeStream == 0) { - Logger.Log($"Bass failed to create a stream while trying to measure loudness: {Bass.LastError}"); + Logger.Log($"Bass failed to create a stream while trying to measure loudness: {Bass.LastError}", level: LogLevel.Error); fileCallbacks.Dispose(); return; } @@ -68,26 +68,24 @@ public TrackLoudness(Stream? data) int loudHandle = BassLoud.Start(decodeStream, BassFlags.BassLoudnessIntegrated | BassFlags.BassLoudnessAutofree, 0); if (loudHandle == 0) - { - Logger.Log($"Failed to start BassLoud: {Bass.LastError}"); - return; - } + throw new InvalidOperationException("Failed to start BassLoud"); while (Bass.ChannelGetData(decodeStream, buffer, buffer.Length) >= 0) { } - float integratedLoudness = 1; - bool gotLevel = BassLoud.GetLevel(loudHandle, BassFlags.BassLoudnessIntegrated, ref integratedLoudness); + float bassIntegratedLoudness = 1; + bool gotLevel = BassLoud.GetLevel(loudHandle, BassFlags.BassLoudnessIntegrated, ref bassIntegratedLoudness); if (!gotLevel) - { - Logger.Log($"Failed to get loudness level: {Bass.LastError}"); - return; - } + throw new InvalidOperationException("Failed to get loudness level"); - if (integratedLoudness < 0) - this.integratedLoudness = integratedLoudness; + if (bassIntegratedLoudness < 0) + integratedLoudness = bassIntegratedLoudness; + } + catch (Exception e) + { + Logger.Error(e, $"{e.Message}: {Bass.LastError}"); } finally { @@ -115,6 +113,8 @@ public TrackLoudness(Stream? data) /// public float? GetIntegratedLoudness() => GetIntegratedLoudnessAsync().GetResultSafely(); + public static double ConvertToVolumeOffset(int targetLevel, float integratedLoudness) => Math.Pow(10, (targetLevel - (double)integratedLoudness) / 20); + protected virtual void Dispose(bool disposing) { if (!disposedValue)