(3dc4135ce) v0.9.5.1
This commit is contained in:
@@ -83,6 +83,8 @@ namespace Barotrauma.Sounds
|
||||
private const int STREAM_BUFFER_SIZE = 8820;
|
||||
private short[] streamShortBuffer;
|
||||
|
||||
private string debugName = "SoundChannel";
|
||||
|
||||
private Vector3? position;
|
||||
public Vector3? Position
|
||||
{
|
||||
@@ -91,7 +93,7 @@ namespace Barotrauma.Sounds
|
||||
{
|
||||
position = value;
|
||||
|
||||
if (ALSourceIndex < 0) return;
|
||||
if (ALSourceIndex < 0) { return; }
|
||||
|
||||
if (position != null)
|
||||
{
|
||||
@@ -100,14 +102,14 @@ namespace Barotrauma.Sounds
|
||||
int alError = Al.GetError();
|
||||
if (alError != Al.NoError)
|
||||
{
|
||||
throw new Exception("Failed to enable source's relative flag: " + Al.GetErrorString(alError));
|
||||
throw new Exception("Failed to enable source's relative flag: " + debugName + ", " + Al.GetErrorString(alError));
|
||||
}
|
||||
|
||||
Al.Source3f(alSource, Al.Position, position.Value.X, position.Value.Y, position.Value.Z);
|
||||
alError = Al.GetError();
|
||||
if (alError != Al.NoError)
|
||||
{
|
||||
throw new Exception("Failed to set source's position: " + Al.GetErrorString(alError));
|
||||
throw new Exception("Failed to set source's position: " + debugName + ", " + Al.GetErrorString(alError));
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -117,14 +119,14 @@ namespace Barotrauma.Sounds
|
||||
int alError = Al.GetError();
|
||||
if (alError != Al.NoError)
|
||||
{
|
||||
throw new Exception("Failed to disable source's relative flag: " + Al.GetErrorString(alError));
|
||||
throw new Exception("Failed to disable source's relative flag: " + debugName + ", " + Al.GetErrorString(alError));
|
||||
}
|
||||
|
||||
Al.Source3f(alSource, Al.Position, 0.0f, 0.0f, 0.0f);
|
||||
alError = Al.GetError();
|
||||
if (alError != Al.NoError)
|
||||
{
|
||||
throw new Exception("Failed to reset source's position: " + Al.GetErrorString(alError));
|
||||
throw new Exception("Failed to reset source's position: " + debugName + ", " + Al.GetErrorString(alError));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -138,7 +140,7 @@ namespace Barotrauma.Sounds
|
||||
{
|
||||
near = value;
|
||||
|
||||
if (ALSourceIndex < 0) return;
|
||||
if (ALSourceIndex < 0) { return; }
|
||||
|
||||
uint alSource = Sound.Owner.GetSourceFromIndex(Sound.SourcePoolIndex, ALSourceIndex);
|
||||
Al.Sourcef(alSource, Al.ReferenceDistance, near);
|
||||
@@ -146,7 +148,7 @@ namespace Barotrauma.Sounds
|
||||
int alError = Al.GetError();
|
||||
if (alError != Al.NoError)
|
||||
{
|
||||
throw new Exception("Failed to set source's reference distance: " + Al.GetErrorString(alError));
|
||||
throw new Exception("Failed to set source's reference distance: " + debugName + ", " + Al.GetErrorString(alError));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -159,14 +161,14 @@ namespace Barotrauma.Sounds
|
||||
{
|
||||
far = value;
|
||||
|
||||
if (ALSourceIndex < 0) return;
|
||||
if (ALSourceIndex < 0) { return; }
|
||||
|
||||
uint alSource = Sound.Owner.GetSourceFromIndex(Sound.SourcePoolIndex, ALSourceIndex);
|
||||
Al.Sourcef(alSource, Al.MaxDistance, far);
|
||||
int alError = Al.GetError();
|
||||
if (alError != Al.NoError)
|
||||
{
|
||||
throw new Exception("Failed to set source's max distance: " + Al.GetErrorString(alError));
|
||||
throw new Exception("Failed to set source's max distance: " + debugName + ", " + Al.GetErrorString(alError));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -179,7 +181,7 @@ namespace Barotrauma.Sounds
|
||||
{
|
||||
gain = Math.Max(Math.Min(value, 1.0f), 0.0f);
|
||||
|
||||
if (ALSourceIndex < 0) return;
|
||||
if (ALSourceIndex < 0) { return; }
|
||||
|
||||
uint alSource = Sound.Owner.GetSourceFromIndex(Sound.SourcePoolIndex, ALSourceIndex);
|
||||
|
||||
@@ -190,7 +192,7 @@ namespace Barotrauma.Sounds
|
||||
int alError = Al.GetError();
|
||||
if (alError != Al.NoError)
|
||||
{
|
||||
throw new Exception("Failed to set source's gain: " + Al.GetErrorString(alError));
|
||||
throw new Exception("Failed to set source's gain: " + debugName + ", " + Al.GetErrorString(alError));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -203,7 +205,7 @@ namespace Barotrauma.Sounds
|
||||
{
|
||||
looping = value;
|
||||
|
||||
if (ALSourceIndex < 0) return;
|
||||
if (ALSourceIndex < 0) { return; }
|
||||
|
||||
if (!IsStream)
|
||||
{
|
||||
@@ -212,7 +214,7 @@ namespace Barotrauma.Sounds
|
||||
int alError = Al.GetError();
|
||||
if (alError != Al.NoError)
|
||||
{
|
||||
throw new Exception("Failed to set source's looping state: " + Al.GetErrorString(alError));
|
||||
throw new Exception("Failed to set source's looping state: " + debugName + ", " + Al.GetErrorString(alError));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -232,11 +234,11 @@ namespace Barotrauma.Sounds
|
||||
get { return muffled; }
|
||||
set
|
||||
{
|
||||
if (muffled == value) return;
|
||||
if (muffled == value) { return; }
|
||||
|
||||
muffled = value;
|
||||
|
||||
if (ALSourceIndex < 0) return;
|
||||
if (ALSourceIndex < 0) { return; }
|
||||
|
||||
if (!IsPlaying) return;
|
||||
|
||||
@@ -247,7 +249,7 @@ namespace Barotrauma.Sounds
|
||||
int alError = Al.GetError();
|
||||
if (alError != Al.NoError)
|
||||
{
|
||||
throw new Exception("Failed to get source's playback position: " + Al.GetErrorString(alError));
|
||||
throw new Exception("Failed to get source's playback position: " + debugName + ", " + Al.GetErrorString(alError));
|
||||
}
|
||||
|
||||
Al.SourceStop(alSource);
|
||||
@@ -255,7 +257,7 @@ namespace Barotrauma.Sounds
|
||||
alError = Al.GetError();
|
||||
if (alError != Al.NoError)
|
||||
{
|
||||
throw new Exception("Failed to stop source: " + Al.GetErrorString(alError));
|
||||
throw new Exception("Failed to stop source: " + debugName + ", " + Al.GetErrorString(alError));
|
||||
}
|
||||
|
||||
Al.Sourcei(alSource, Al.Buffer, muffled ? (int)Sound.ALMuffledBuffer : (int)Sound.ALBuffer);
|
||||
@@ -263,21 +265,21 @@ namespace Barotrauma.Sounds
|
||||
alError = Al.GetError();
|
||||
if (alError != Al.NoError)
|
||||
{
|
||||
throw new Exception("Failed to bind buffer to source: " + Al.GetErrorString(alError));
|
||||
throw new Exception("Failed to bind buffer to source: " + debugName + ", " + Al.GetErrorString(alError));
|
||||
}
|
||||
|
||||
Al.SourcePlay(alSource);
|
||||
alError = Al.GetError();
|
||||
if (alError != Al.NoError)
|
||||
{
|
||||
throw new Exception("Failed to replay source: " + Al.GetErrorString(alError));
|
||||
throw new Exception("Failed to replay source: " + debugName + ", " + Al.GetErrorString(alError));
|
||||
}
|
||||
|
||||
Al.Sourcei(alSource, Al.SampleOffset, playbackPos);
|
||||
alError = Al.GetError();
|
||||
if (alError != Al.NoError)
|
||||
{
|
||||
throw new Exception("Failed to reset playback position: " + Al.GetErrorString(alError));
|
||||
throw new Exception("Failed to reset playback position: " + debugName + ", " + Al.GetErrorString(alError));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -290,7 +292,7 @@ namespace Barotrauma.Sounds
|
||||
{
|
||||
if (!IsPlaying) { return 0.0f; }
|
||||
|
||||
uint alSource = Sound.Owner.GetSourceFromIndex(Sound.SourcePoolIndex, ALSourceIndex);
|
||||
uint alSource = Sound?.Owner?.GetSourceFromIndex(Sound.SourcePoolIndex, ALSourceIndex) ?? 0;
|
||||
|
||||
if (alSource == 0) { return 0.0f; }
|
||||
|
||||
@@ -300,7 +302,7 @@ namespace Barotrauma.Sounds
|
||||
int alError = Al.GetError();
|
||||
if (alError != Al.NoError)
|
||||
{
|
||||
throw new Exception("Failed to get source's playback position: " + Al.GetErrorString(alError));
|
||||
throw new Exception("Failed to get source's playback position: " + debugName + ", " + Al.GetErrorString(alError));
|
||||
}
|
||||
return Sound.GetAmplitudeAtPlaybackPos(playbackPos);
|
||||
}
|
||||
@@ -367,7 +369,7 @@ namespace Barotrauma.Sounds
|
||||
int alError = Al.GetError();
|
||||
if (alError != Al.NoError)
|
||||
{
|
||||
throw new Exception("Failed to determine playing state from source: " + Al.GetErrorString(alError));
|
||||
throw new Exception("Failed to determine playing state from source: " + debugName + ", " + Al.GetErrorString(alError));
|
||||
}
|
||||
return playing;
|
||||
}
|
||||
@@ -377,6 +379,10 @@ namespace Barotrauma.Sounds
|
||||
{
|
||||
Sound = sound;
|
||||
|
||||
debugName = sound == null ?
|
||||
"SoundChannel (null)" :
|
||||
$"SoundChannel ({(string.IsNullOrEmpty(sound.Filename) ? "filename empty" : sound.Filename) })";
|
||||
|
||||
IsStream = sound.Stream;
|
||||
FilledByNetwork = sound is VoipSound;
|
||||
decayTimer = 0;
|
||||
@@ -405,7 +411,7 @@ namespace Barotrauma.Sounds
|
||||
int alError = Al.GetError();
|
||||
if (alError != Al.NoError)
|
||||
{
|
||||
throw new Exception("Failed to reset source buffer: " + Al.GetErrorString(alError));
|
||||
throw new Exception("Failed to reset source buffer: " + debugName + ", " + Al.GetErrorString(alError));
|
||||
}
|
||||
|
||||
if (!Al.IsBuffer(sound.ALBuffer))
|
||||
@@ -418,14 +424,14 @@ namespace Barotrauma.Sounds
|
||||
alError = Al.GetError();
|
||||
if (alError != Al.NoError)
|
||||
{
|
||||
throw new Exception("Failed to bind buffer to source (" + ALSourceIndex.ToString() + ":" + sound.Owner.GetSourceFromIndex(Sound.SourcePoolIndex, ALSourceIndex) + "," + sound.ALBuffer.ToString() + "): " + Al.GetErrorString(alError));
|
||||
throw new Exception("Failed to bind buffer to source (" + ALSourceIndex.ToString() + ":" + sound.Owner.GetSourceFromIndex(Sound.SourcePoolIndex, ALSourceIndex) + "," + sound.ALBuffer.ToString() + "): " + debugName + ", " + Al.GetErrorString(alError));
|
||||
}
|
||||
|
||||
Al.SourcePlay(sound.Owner.GetSourceFromIndex(Sound.SourcePoolIndex, ALSourceIndex));
|
||||
alError = Al.GetError();
|
||||
if (alError != Al.NoError)
|
||||
{
|
||||
throw new Exception("Failed to play source: " + Al.GetErrorString(alError));
|
||||
throw new Exception("Failed to play source: " + debugName + ", " + Al.GetErrorString(alError));
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -435,14 +441,14 @@ namespace Barotrauma.Sounds
|
||||
int alError = Al.GetError();
|
||||
if (alError != Al.NoError)
|
||||
{
|
||||
throw new Exception("Failed to reset source buffer: " + Al.GetErrorString(alError));
|
||||
throw new Exception("Failed to reset source buffer: " + debugName + ", " + Al.GetErrorString(alError));
|
||||
}
|
||||
|
||||
Al.Sourcei(sound.Owner.GetSourceFromIndex(Sound.SourcePoolIndex, ALSourceIndex), Al.Looping, Al.False);
|
||||
alError = Al.GetError();
|
||||
if (alError != Al.NoError)
|
||||
{
|
||||
throw new Exception("Failed to set stream looping state: " + Al.GetErrorString(alError));
|
||||
throw new Exception("Failed to set stream looping state: " + debugName + ", " + Al.GetErrorString(alError));
|
||||
}
|
||||
|
||||
streamShortBuffer = new short[STREAM_BUFFER_SIZE];
|
||||
@@ -457,12 +463,12 @@ namespace Barotrauma.Sounds
|
||||
alError = Al.GetError();
|
||||
if (alError != Al.NoError)
|
||||
{
|
||||
throw new Exception("Failed to generate stream buffers: " + Al.GetErrorString(alError));
|
||||
throw new Exception("Failed to generate stream buffers: " + debugName + ", " + Al.GetErrorString(alError));
|
||||
}
|
||||
|
||||
if (!Al.IsBuffer(streamBuffers[i]))
|
||||
{
|
||||
throw new Exception("Generated streamBuffer[" + i.ToString() + "] is invalid!");
|
||||
throw new Exception("Generated streamBuffer[" + i.ToString() + "] is invalid! " + debugName);
|
||||
}
|
||||
}
|
||||
Sound.Owner.InitStreamThread();
|
||||
@@ -488,6 +494,11 @@ namespace Barotrauma.Sounds
|
||||
Sound.Owner.Update();
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return debugName;
|
||||
}
|
||||
|
||||
public bool FadingOutAndDisposing;
|
||||
public void FadeOutAndDispose()
|
||||
{
|
||||
@@ -505,7 +516,7 @@ namespace Barotrauma.Sounds
|
||||
int alError = Al.GetError();
|
||||
if (alError != Al.NoError)
|
||||
{
|
||||
throw new Exception("Failed to stop source: " + Al.GetErrorString(alError));
|
||||
throw new Exception("Failed to stop source: " + debugName + ", " + Al.GetErrorString(alError));
|
||||
}
|
||||
|
||||
if (IsStream)
|
||||
@@ -516,7 +527,7 @@ namespace Barotrauma.Sounds
|
||||
alError = Al.GetError();
|
||||
if (alError != Al.NoError)
|
||||
{
|
||||
throw new Exception("Failed to stop streamed source: " + Al.GetErrorString(alError));
|
||||
throw new Exception("Failed to stop streamed source: " + debugName + ", " + Al.GetErrorString(alError));
|
||||
}
|
||||
|
||||
int buffersToRequeue = 0;
|
||||
@@ -526,21 +537,21 @@ namespace Barotrauma.Sounds
|
||||
alError = Al.GetError();
|
||||
if (alError != Al.NoError)
|
||||
{
|
||||
throw new Exception("Failed to determine processed buffers from streamed source: " + Al.GetErrorString(alError));
|
||||
throw new Exception("Failed to determine processed buffers from streamed source: " + debugName + ", " + Al.GetErrorString(alError));
|
||||
}
|
||||
|
||||
Al.SourceUnqueueBuffers(alSource, buffersToRequeue, unqueuedBuffers);
|
||||
alError = Al.GetError();
|
||||
if (alError != Al.NoError)
|
||||
{
|
||||
throw new Exception("Failed to unqueue buffers from streamed source: " + Al.GetErrorString(alError));
|
||||
throw new Exception("Failed to unqueue buffers from streamed source: " + debugName + ", " + Al.GetErrorString(alError));
|
||||
}
|
||||
|
||||
Al.Sourcei(alSource, Al.Buffer, 0);
|
||||
alError = Al.GetError();
|
||||
if (alError != Al.NoError)
|
||||
{
|
||||
throw new Exception("Failed to reset buffer for streamed source: " + Al.GetErrorString(alError));
|
||||
throw new Exception("Failed to reset buffer for streamed source: " + debugName + ", " + Al.GetErrorString(alError));
|
||||
}
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
@@ -549,7 +560,7 @@ namespace Barotrauma.Sounds
|
||||
alError = Al.GetError();
|
||||
if (alError != Al.NoError)
|
||||
{
|
||||
throw new Exception("Failed to delete streamBuffers[" + i.ToString() + "] ("+streamBuffers[i].ToString()+"): " + Al.GetErrorString(alError));
|
||||
throw new Exception("Failed to delete streamBuffers[" + i.ToString() + "] (" + streamBuffers[i].ToString() + "): " + debugName + ", " + Al.GetErrorString(alError));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -561,11 +572,12 @@ namespace Barotrauma.Sounds
|
||||
alError = Al.GetError();
|
||||
if (alError != Al.NoError)
|
||||
{
|
||||
throw new Exception("Failed to unbind buffer to non-streamed source: " + Al.GetErrorString(alError));
|
||||
throw new Exception("Failed to unbind buffer to non-streamed source: " + debugName + ", " + Al.GetErrorString(alError));
|
||||
}
|
||||
}
|
||||
|
||||
ALSourceIndex = -1;
|
||||
debugName += " [DISPOSED]";
|
||||
}
|
||||
}
|
||||
finally
|
||||
@@ -576,7 +588,7 @@ namespace Barotrauma.Sounds
|
||||
|
||||
public void UpdateStream()
|
||||
{
|
||||
if (!IsStream) throw new Exception("Called UpdateStream on a non-streamed sound channel!");
|
||||
if (!IsStream) { throw new Exception("Called UpdateStream on a non-streamed sound channel!"); }
|
||||
|
||||
try
|
||||
{
|
||||
@@ -591,7 +603,7 @@ namespace Barotrauma.Sounds
|
||||
int alError = Al.GetError();
|
||||
if (alError != Al.NoError)
|
||||
{
|
||||
throw new Exception("Failed to determine playing state from streamed source: " + Al.GetErrorString(alError));
|
||||
throw new Exception("Failed to determine playing state from streamed source: " + debugName + ", " + Al.GetErrorString(alError));
|
||||
}
|
||||
|
||||
int unqueuedBufferCount;
|
||||
@@ -599,16 +611,16 @@ namespace Barotrauma.Sounds
|
||||
alError = Al.GetError();
|
||||
if (alError != Al.NoError)
|
||||
{
|
||||
throw new Exception("Failed to determine processed buffers from streamed source: " + Al.GetErrorString(alError));
|
||||
throw new Exception("Failed to determine processed buffers from streamed source: " + debugName + ", " + Al.GetErrorString(alError));
|
||||
}
|
||||
|
||||
Al.SourceUnqueueBuffers(alSource, unqueuedBufferCount, unqueuedBuffers);
|
||||
alError = Al.GetError();
|
||||
if (alError != Al.NoError)
|
||||
{
|
||||
throw new Exception("Failed to unqueue buffers from streamed source: " + Al.GetErrorString(alError));
|
||||
throw new Exception("Failed to unqueue buffers from streamed source: " + debugName + ", " + Al.GetErrorString(alError));
|
||||
}
|
||||
|
||||
|
||||
buffersToRequeue += unqueuedBufferCount;
|
||||
|
||||
int iterCount = buffersToRequeue;
|
||||
@@ -619,7 +631,7 @@ namespace Barotrauma.Sounds
|
||||
int readSamples = Sound.FillStreamBuffer(streamSeekPos, buffer);
|
||||
float readAmplitude = 0.0f;
|
||||
|
||||
for (int i=0;i<Math.Min(readSamples, buffer.Length);i++)
|
||||
for (int i = 0; i < Math.Min(readSamples, buffer.Length); i++)
|
||||
{
|
||||
float sampleF = ((float)buffer[i]) / ((float)short.MaxValue);
|
||||
readAmplitude = Math.Max(readAmplitude, Math.Abs(sampleF));
|
||||
@@ -672,7 +684,7 @@ namespace Barotrauma.Sounds
|
||||
if (alError != Al.NoError)
|
||||
{
|
||||
throw new Exception("Failed to assign data to stream buffer: " +
|
||||
Al.GetErrorString(alError) + ": " + streamBuffers[index].ToString() + "/" + streamBuffers.Length + ", readSamples: " + readSamples);
|
||||
Al.GetErrorString(alError) + ": " + streamBuffers[index].ToString() + "/" + streamBuffers.Length + ", readSamples: " + readSamples + ", " + debugName);
|
||||
}
|
||||
|
||||
Al.SourceQueueBuffer(alSource, streamBuffers[index]);
|
||||
@@ -681,7 +693,7 @@ namespace Barotrauma.Sounds
|
||||
alError = Al.GetError();
|
||||
if (alError != Al.NoError)
|
||||
{
|
||||
throw new Exception("Failed to queue streamBuffer[" + index.ToString() + "] to stream: " + Al.GetErrorString(alError));
|
||||
throw new Exception("Failed to queue streamBuffer[" + index.ToString() + "] to stream: " + debugName + ", " + Al.GetErrorString(alError));
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user