Skip to content

Commit

Permalink
Fix variable hiding and throw instead of log in TrackLoudness
Browse files Browse the repository at this point in the history
  • Loading branch information
hwsmm committed May 13, 2024
1 parent 88450e1 commit 8992651
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions osu.Framework/Audio/Track/TrackLoudness.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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
{
Expand Down Expand Up @@ -115,6 +113,8 @@ public TrackLoudness(Stream? data)
/// </summary>
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)
Expand Down

0 comments on commit 8992651

Please sign in to comment.