Add better OpenAL logging (#4687)

This commit is contained in:
metalgearsloth
2023-12-10 21:25:43 +11:00
committed by GitHub
parent 1772651049
commit a2cd33afe5
3 changed files with 24 additions and 5 deletions

View File

@@ -216,6 +216,13 @@ internal partial class AudioManager
public void SetMasterGain(float newGain)
{
if (newGain < 0f)
{
OpenALSawmill.Error("Tried to set master gain below 0, clamping to 0");
AL.Listener(ALListenerf.Gain, 0f);
return;
}
AL.Listener(ALListenerf.Gain, newGain);
}

View File

@@ -140,6 +140,18 @@ internal sealed partial class AudioManager : IAudioInternal
}
}
/// <summary>
/// Like _checkAlError but allows custom data to be passed in as relevant.
/// </summary>
internal void LogALError(string message, [CallerMemberName] string callerMember = "", [CallerLineNumber] int callerLineNumber = -1)
{
var error = AL.GetError();
if (error != ALError.NoError)
{
OpenALSawmill.Error("[{0}:{1}] AL error: {2}, {3}", callerMember, callerLineNumber, error, message);
}
}
public void _checkAlError([CallerMemberName] string callerMember = "", [CallerLineNumber] int callerLineNumber = -1)
{
var error = AL.GetError();

View File

@@ -194,7 +194,7 @@ internal abstract class BaseAudioSource : IAudioSource
_gain = value;
AL.Source(SourceHandle, ALSourcef.Gain, _gain * priorOcclusion);
Master._checkAlError();
Master.LogALError($"Gain is {_gain:0.00} and priorOcclusion is {priorOcclusion:0.00}. EFX supported: {IsEfxSupported}");
}
}
@@ -212,7 +212,7 @@ internal abstract class BaseAudioSource : IAudioSource
{
_checkDisposed();
AL.Source(SourceHandle, ALSourcef.MaxDistance, value);
Master._checkAlError();
Master.LogALError($"MaxDistance is {value:0.00}");
}
}
@@ -230,7 +230,7 @@ internal abstract class BaseAudioSource : IAudioSource
{
_checkDisposed();
AL.Source(SourceHandle, ALSourcef.RolloffFactor, value);
Master._checkAlError();
Master.LogALError($"RolloffFactor is {value:0.00}");
}
}
@@ -248,7 +248,7 @@ internal abstract class BaseAudioSource : IAudioSource
{
_checkDisposed();
AL.Source(SourceHandle, ALSourcef.ReferenceDistance, value);
Master._checkAlError();
Master.LogALError($"ReferenceDistance is {value:0.00}");
}
}
@@ -294,7 +294,7 @@ internal abstract class BaseAudioSource : IAudioSource
{
_checkDisposed();
AL.Source(SourceHandle, ALSourcef.SecOffset, value);
Master._checkAlError();
Master._checkAlError($"Tried to set invalid playback position of {value:0.00}");
}
}