Added some extra information to OpenAL error messages
This commit is contained in:
@@ -56,7 +56,7 @@ namespace Barotrauma.Sounds
|
|||||||
AL.BufferData(sound.alBufferId, reader.Channels == 1 ? ALFormat.Mono16 : ALFormat.Stereo16, sound.castBuffer,
|
AL.BufferData(sound.alBufferId, reader.Channels == 1 ? ALFormat.Mono16 : ALFormat.Stereo16, sound.castBuffer,
|
||||||
readSamples * sizeof(short), reader.SampleRate);
|
readSamples * sizeof(short), reader.SampleRate);
|
||||||
|
|
||||||
ALHelper.Check();
|
ALHelper.Check(oggFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
//AL.Source(alSourceId, ALSourcei.Buffer, alBufferId);
|
//AL.Source(alSourceId, ALSourcei.Buffer, alBufferId);
|
||||||
@@ -100,12 +100,12 @@ namespace Barotrauma.Sounds
|
|||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
//var state = AL.GetSourceState(alSourceId);
|
|
||||||
//if (state == ALSourceState.Playing || state == ALSourceState.Paused)
|
|
||||||
// Stop();
|
|
||||||
System.Diagnostics.Debug.WriteLine(alBufferId);
|
System.Diagnostics.Debug.WriteLine(alBufferId);
|
||||||
//AL.DeleteSource(alSourceId);
|
if (alBufferId > 0)
|
||||||
AL.DeleteBuffer(alBufferId);
|
{
|
||||||
|
AL.DeleteBuffer(alBufferId);
|
||||||
|
alBufferId = 0;
|
||||||
|
}
|
||||||
|
|
||||||
//if (ALHelper.Efx.IsInitialized)
|
//if (ALHelper.Efx.IsInitialized)
|
||||||
// ALHelper.Efx.DeleteFilter(alFilterId);
|
// ALHelper.Efx.DeleteFilter(alFilterId);
|
||||||
|
|||||||
@@ -45,20 +45,24 @@ namespace Barotrauma.Sounds
|
|||||||
//logHandler(String.Format("Total memory : {0:0.###} {1} ", usedHeap, sizes[order]), 0, 6);
|
//logHandler(String.Format("Total memory : {0:0.###} {1} ", usedHeap, sizes[order]), 0, 6);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Check()
|
public static void Check(string extraErrorMsg = "")
|
||||||
{
|
{
|
||||||
ALError error;
|
ALError error;
|
||||||
if ((error = AL.GetError()) != ALError.NoError)
|
if ((error = AL.GetError()) != ALError.NoError)
|
||||||
{
|
{
|
||||||
|
string errorMsg = "OpenAL error: " + AL.GetErrorString(error);
|
||||||
|
if (!string.IsNullOrEmpty(extraErrorMsg)) errorMsg += " {" + extraErrorMsg + "} ";
|
||||||
|
errorMsg += "\n" + Environment.StackTrace;
|
||||||
|
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
DebugConsole.ThrowError("OpenAL error: " + AL.GetErrorString(error) + "\n" + Environment.StackTrace);
|
DebugConsole.ThrowError(errorMsg);
|
||||||
#else
|
#else
|
||||||
DebugConsole.NewMessage("OpenAL error: " + AL.GetErrorString(error) + "\n" + Environment.StackTrace, Microsoft.Xna.Framework.Color.Red);
|
DebugConsole.NewMessage(errorMsg, Microsoft.Xna.Framework.Color.Red);
|
||||||
#endif
|
#endif
|
||||||
GameAnalyticsManager.AddErrorEventOnce(
|
GameAnalyticsManager.AddErrorEventOnce(
|
||||||
"OggStream.Check:"+ AL.GetErrorString(error),
|
"OggStream.Check:" + AL.GetErrorString(error) + extraErrorMsg,
|
||||||
GameAnalyticsSDK.Net.EGAErrorSeverity.Error,
|
GameAnalyticsSDK.Net.EGAErrorSeverity.Error,
|
||||||
"OpenAL error: " + AL.GetErrorString(error) + "\n" + Environment.StackTrace);
|
errorMsg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -87,9 +91,17 @@ namespace Barotrauma.Sounds
|
|||||||
public Action<string, int, int> LogHandler;
|
public Action<string, int, int> LogHandler;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
public OggStream(string filename, int bufferCount = DefaultBufferCount) : this(File.OpenRead(filename), bufferCount) { }
|
public string FileName
|
||||||
public OggStream(Stream stream, int bufferCount = DefaultBufferCount)
|
|
||||||
{
|
{
|
||||||
|
get;
|
||||||
|
private set;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OggStream(string filename, int bufferCount = DefaultBufferCount) : this(File.OpenRead(filename), filename, bufferCount) { }
|
||||||
|
public OggStream(Stream stream, string fileName, int bufferCount = DefaultBufferCount)
|
||||||
|
{
|
||||||
|
this.FileName = fileName;
|
||||||
|
|
||||||
BufferCount = bufferCount;
|
BufferCount = bufferCount;
|
||||||
|
|
||||||
alBufferIds = AL.GenBuffers(bufferCount);
|
alBufferIds = AL.GenBuffers(bufferCount);
|
||||||
@@ -98,7 +110,7 @@ namespace Barotrauma.Sounds
|
|||||||
if (ALHelper.XRam.IsInitialized)
|
if (ALHelper.XRam.IsInitialized)
|
||||||
{
|
{
|
||||||
ALHelper.XRam.SetBufferMode(BufferCount, ref alBufferIds[0], XRamExtension.XRamStorage.Hardware);
|
ALHelper.XRam.SetBufferMode(BufferCount, ref alBufferIds[0], XRamExtension.XRamStorage.Hardware);
|
||||||
ALHelper.Check();
|
ALHelper.Check(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ALHelper.Efx.IsInitialized)
|
if (ALHelper.Efx.IsInitialized)
|
||||||
@@ -167,7 +179,7 @@ namespace Barotrauma.Sounds
|
|||||||
|
|
||||||
AL.SourcePlay(alSourceId);
|
AL.SourcePlay(alSourceId);
|
||||||
this.Volume = volume;
|
this.Volume = volume;
|
||||||
ALHelper.Check();
|
ALHelper.Check(FileName);
|
||||||
|
|
||||||
Preparing = false;
|
Preparing = false;
|
||||||
|
|
||||||
@@ -181,7 +193,7 @@ namespace Barotrauma.Sounds
|
|||||||
|
|
||||||
OggStreamer.Instance.RemoveStream(this);
|
OggStreamer.Instance.RemoveStream(this);
|
||||||
AL.SourcePause(alSourceId);
|
AL.SourcePause(alSourceId);
|
||||||
ALHelper.Check();
|
ALHelper.Check(FileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Resume()
|
public void Resume()
|
||||||
@@ -191,7 +203,7 @@ namespace Barotrauma.Sounds
|
|||||||
|
|
||||||
OggStreamer.Instance.AddStream(this);
|
OggStreamer.Instance.AddStream(this);
|
||||||
AL.SourcePlay(alSourceId);
|
AL.SourcePlay(alSourceId);
|
||||||
ALHelper.Check();
|
ALHelper.Check(FileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Stop()
|
public void Stop()
|
||||||
@@ -230,7 +242,7 @@ namespace Barotrauma.Sounds
|
|||||||
set
|
set
|
||||||
{
|
{
|
||||||
AL.Source(alSourceId, ALSourcef.Gain, volume = value);
|
AL.Source(alSourceId, ALSourcef.Gain, volume = value);
|
||||||
ALHelper.Check();
|
ALHelper.Check(FileName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -260,20 +272,20 @@ namespace Barotrauma.Sounds
|
|||||||
/*if (ALHelper.Efx.IsInitialized)
|
/*if (ALHelper.Efx.IsInitialized)
|
||||||
ALHelper.Efx.DeleteFilter(alFilterId);*/
|
ALHelper.Efx.DeleteFilter(alFilterId);*/
|
||||||
|
|
||||||
ALHelper.Check();
|
ALHelper.Check(FileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
void StopPlayback()
|
void StopPlayback()
|
||||||
{
|
{
|
||||||
AL.SourceStop(alSourceId);
|
AL.SourceStop(alSourceId);
|
||||||
ALHelper.Check();
|
ALHelper.Check(FileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Empty()
|
void Empty()
|
||||||
{
|
{
|
||||||
int queued;
|
int queued;
|
||||||
AL.GetSource(alSourceId, ALGetSourcei.BuffersQueued, out queued);
|
AL.GetSource(alSourceId, ALGetSourcei.BuffersQueued, out queued);
|
||||||
ALHelper.Check();
|
ALHelper.Check(FileName);
|
||||||
|
|
||||||
if (queued > 0)
|
if (queued > 0)
|
||||||
{
|
{
|
||||||
@@ -296,12 +308,12 @@ namespace Barotrauma.Sounds
|
|||||||
if (processed > 0)
|
if (processed > 0)
|
||||||
{
|
{
|
||||||
AL.SourceUnqueueBuffers(alSourceId, processed, salvaged);
|
AL.SourceUnqueueBuffers(alSourceId, processed, salvaged);
|
||||||
ALHelper.Check();
|
ALHelper.Check(FileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try turning it off again?
|
// Try turning it off again?
|
||||||
AL.SourceStop(alSourceId);
|
AL.SourceStop(alSourceId);
|
||||||
ALHelper.Check();
|
ALHelper.Check(FileName);
|
||||||
|
|
||||||
Empty();
|
Empty();
|
||||||
}
|
}
|
||||||
@@ -318,7 +330,7 @@ namespace Barotrauma.Sounds
|
|||||||
// Fill first buffer synchronously
|
// Fill first buffer synchronously
|
||||||
OggStreamer.Instance.FillBuffer(this, alBufferIds[0]);
|
OggStreamer.Instance.FillBuffer(this, alBufferIds[0]);
|
||||||
AL.SourceQueueBuffer(alSourceId, alBufferIds[0]);
|
AL.SourceQueueBuffer(alSourceId, alBufferIds[0]);
|
||||||
ALHelper.Check();
|
ALHelper.Check(FileName);
|
||||||
|
|
||||||
// Schedule the others asynchronously
|
// Schedule the others asynchronously
|
||||||
OggStreamer.Instance.AddStream(this);
|
OggStreamer.Instance.AddStream(this);
|
||||||
@@ -433,7 +445,7 @@ namespace Barotrauma.Sounds
|
|||||||
}
|
}
|
||||||
AL.BufferData(bufferId, stream.Reader.Channels == 1 ? ALFormat.Mono16 : ALFormat.Stereo16, castBuffer,
|
AL.BufferData(bufferId, stream.Reader.Channels == 1 ? ALFormat.Mono16 : ALFormat.Stereo16, castBuffer,
|
||||||
readSamples * sizeof(short), stream.Reader.SampleRate);
|
readSamples * sizeof(short), stream.Reader.SampleRate);
|
||||||
ALHelper.Check();
|
ALHelper.Check(stream.FileName);
|
||||||
|
|
||||||
return readSamples != BufferSize;
|
return readSamples != BufferSize;
|
||||||
}
|
}
|
||||||
@@ -470,10 +482,10 @@ namespace Barotrauma.Sounds
|
|||||||
|
|
||||||
int queued;
|
int queued;
|
||||||
AL.GetSource(stream.alSourceId, ALGetSourcei.BuffersQueued, out queued);
|
AL.GetSource(stream.alSourceId, ALGetSourcei.BuffersQueued, out queued);
|
||||||
ALHelper.Check();
|
ALHelper.Check(stream.FileName);
|
||||||
int processed;
|
int processed;
|
||||||
AL.GetSource(stream.alSourceId, ALGetSourcei.BuffersProcessed, out processed);
|
AL.GetSource(stream.alSourceId, ALGetSourcei.BuffersProcessed, out processed);
|
||||||
ALHelper.Check();
|
ALHelper.Check(stream.FileName);
|
||||||
|
|
||||||
if (processed == 0 && queued == stream.BufferCount) continue;
|
if (processed == 0 && queued == stream.BufferCount) continue;
|
||||||
|
|
||||||
@@ -500,7 +512,7 @@ namespace Barotrauma.Sounds
|
|||||||
}
|
}
|
||||||
|
|
||||||
AL.SourceQueueBuffers(stream.alSourceId, tempBuffers.Length, tempBuffers);
|
AL.SourceQueueBuffers(stream.alSourceId, tempBuffers.Length, tempBuffers);
|
||||||
ALHelper.Check();
|
ALHelper.Check(stream.FileName);
|
||||||
|
|
||||||
if (finished && !stream.IsLooped)
|
if (finished && !stream.IsLooped)
|
||||||
continue;
|
continue;
|
||||||
@@ -518,7 +530,7 @@ namespace Barotrauma.Sounds
|
|||||||
if (state == ALSourceState.Stopped)
|
if (state == ALSourceState.Stopped)
|
||||||
{
|
{
|
||||||
AL.SourcePlay(stream.alSourceId);
|
AL.SourcePlay(stream.alSourceId);
|
||||||
ALHelper.Check();
|
ALHelper.Check(stream.FileName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ namespace Barotrauma
|
|||||||
{
|
{
|
||||||
DebugConsole.ThrowError("Failed to load sound "+file+"!", e);
|
DebugConsole.ThrowError("Failed to load sound "+file+"!", e);
|
||||||
}
|
}
|
||||||
ALHelper.Check();
|
ALHelper.Check(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
baseVolume = 1.0f;
|
baseVolume = 1.0f;
|
||||||
@@ -219,7 +219,7 @@ namespace Barotrauma
|
|||||||
(SoundManager.IsPlaying(alSourceId) || SoundManager.IsPaused(alSourceId)))
|
(SoundManager.IsPlaying(alSourceId) || SoundManager.IsPaused(alSourceId)))
|
||||||
{
|
{
|
||||||
SoundManager.Stop(alSourceId);
|
SoundManager.Stop(alSourceId);
|
||||||
ALHelper.Check();
|
ALHelper.Check(filePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (Sound s in loadedSounds)
|
foreach (Sound s in loadedSounds)
|
||||||
@@ -228,7 +228,7 @@ namespace Barotrauma
|
|||||||
}
|
}
|
||||||
|
|
||||||
SoundManager.ClearAlSource(AlBufferId);
|
SoundManager.ClearAlSource(AlBufferId);
|
||||||
ALHelper.Check();
|
ALHelper.Check(filePath);
|
||||||
|
|
||||||
if (oggSound != null)
|
if (oggSound != null)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -143,7 +143,7 @@ namespace Barotrauma.Sounds
|
|||||||
volume = 0.0f;
|
volume = 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sourceIndex<1 || soundsPlaying[sourceIndex] != sound)
|
if (sourceIndex < 1 || soundsPlaying[sourceIndex] != sound)
|
||||||
{
|
{
|
||||||
sourceIndex = Play(sound, position, volume, 0.0f, true);
|
sourceIndex = Play(sound, position, volume, 0.0f, true);
|
||||||
}
|
}
|
||||||
@@ -153,7 +153,7 @@ namespace Barotrauma.Sounds
|
|||||||
AL.Source(alSources[sourceIndex], ALSourceb.Looping, true);
|
AL.Source(alSources[sourceIndex], ALSourceb.Looping, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
ALHelper.Check();
|
ALHelper.Check(sound?.FilePath);
|
||||||
return sourceIndex;
|
return sourceIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -165,7 +165,7 @@ namespace Barotrauma.Sounds
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
AL.SourcePause(alSources[sourceIndex]);
|
AL.SourcePause(alSources[sourceIndex]);
|
||||||
ALHelper.Check();
|
ALHelper.Check(soundsPlaying[sourceIndex]?.FilePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Resume(int sourceIndex)
|
public static void Resume(int sourceIndex)
|
||||||
@@ -176,7 +176,7 @@ namespace Barotrauma.Sounds
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
AL.SourcePlay(alSources[sourceIndex]);
|
AL.SourcePlay(alSources[sourceIndex]);
|
||||||
ALHelper.Check();
|
ALHelper.Check(soundsPlaying[sourceIndex]?.FilePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Stop(int sourceIndex)
|
public static void Stop(int sourceIndex)
|
||||||
@@ -291,7 +291,7 @@ namespace Barotrauma.Sounds
|
|||||||
|
|
||||||
ALHelper.Efx.Filter(lowpassFilterId, OpenTK.Audio.OpenAL.EfxFilterf.LowpassGainHF, lowPassHfGain = value);
|
ALHelper.Efx.Filter(lowpassFilterId, OpenTK.Audio.OpenAL.EfxFilterf.LowpassGainHF, lowPassHfGain = value);
|
||||||
ALHelper.Efx.BindFilterToSource(alSources[i], lowpassFilterId);
|
ALHelper.Efx.BindFilterToSource(alSources[i], lowpassFilterId);
|
||||||
ALHelper.Check();
|
ALHelper.Check(soundsPlaying[i]?.FilePath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -316,7 +316,7 @@ namespace Barotrauma.Sounds
|
|||||||
|
|
||||||
ALHelper.Efx.Filter(lowpassFilterId, OpenTK.Audio.OpenAL.EfxFilterf.LowpassGainHF, lowPassGain);
|
ALHelper.Efx.Filter(lowpassFilterId, OpenTK.Audio.OpenAL.EfxFilterf.LowpassGainHF, lowPassGain);
|
||||||
ALHelper.Efx.BindFilterToSource(alSources[sourceIndex], lowpassFilterId);
|
ALHelper.Efx.BindFilterToSource(alSources[sourceIndex], lowpassFilterId);
|
||||||
ALHelper.Check();
|
ALHelper.Check(soundsPlaying[sourceIndex]?.FilePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static OggStream StartStream(string file, float volume = 1.0f)
|
public static OggStream StartStream(string file, float volume = 1.0f)
|
||||||
@@ -331,7 +331,7 @@ namespace Barotrauma.Sounds
|
|||||||
|
|
||||||
oggStream.Play(volume);
|
oggStream.Play(volume);
|
||||||
|
|
||||||
ALHelper.Check();
|
ALHelper.Check(file);
|
||||||
|
|
||||||
return oggStream;
|
return oggStream;
|
||||||
}
|
}
|
||||||
@@ -361,15 +361,15 @@ namespace Barotrauma.Sounds
|
|||||||
|
|
||||||
for (int i = 0; i < DefaultSourceCount; i++)
|
for (int i = 0; i < DefaultSourceCount; i++)
|
||||||
{
|
{
|
||||||
|
string soundPath = soundsPlaying[i]?.FilePath;
|
||||||
var state = OpenTK.Audio.OpenAL.AL.GetSourceState(alSources[i]);
|
var state = OpenTK.Audio.OpenAL.AL.GetSourceState(alSources[i]);
|
||||||
if (state == OpenTK.Audio.OpenAL.ALSourceState.Playing || state == OpenTK.Audio.OpenAL.ALSourceState.Paused)
|
if (state == OpenTK.Audio.OpenAL.ALSourceState.Playing || state == OpenTK.Audio.OpenAL.ALSourceState.Paused)
|
||||||
{
|
{
|
||||||
Stop(i);
|
Stop(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
OpenTK.Audio.OpenAL.AL.DeleteSource(alSources[i]);
|
OpenTK.Audio.OpenAL.AL.DeleteSource(alSources[i]);
|
||||||
|
ALHelper.Check(soundPath);
|
||||||
ALHelper.Check();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (oggStream != null)
|
if (oggStream != null)
|
||||||
|
|||||||
Reference in New Issue
Block a user