(a410fd46c) Trying to help the merge script through a jungle of merges

This commit is contained in:
Joonas Rikkonen
2019-06-04 16:19:53 +03:00
parent 5208b922d8
commit bea7b58ff3
84 changed files with 1720 additions and 929 deletions
@@ -1,5 +1,5 @@
using System;
using OpenTK.Audio.OpenAL;
using OpenAL;
using NVorbis;
using System.Collections.Generic;
@@ -21,7 +21,7 @@ namespace Barotrauma.Sounds
reader = new VorbisReader(filename);
ALFormat = reader.Channels == 1 ? ALFormat.Mono16 : ALFormat.Stereo16;
ALFormat = reader.Channels == 1 ? Al.FormatMono16 : Al.FormatStereo16;
SampleRate = reader.SampleRate;
if (!stream)
@@ -35,26 +35,26 @@ namespace Barotrauma.Sounds
CastBuffer(floatBuffer, shortBuffer, readSamples);
AL.BufferData((int)ALBuffer, ALFormat, shortBuffer,
Al.BufferData(ALBuffer, ALFormat, shortBuffer,
readSamples * sizeof(short), SampleRate);
ALError alError = AL.GetError();
if (alError != ALError.NoError)
int alError = Al.GetError();
if (alError != Al.NoError)
{
throw new Exception("Failed to set buffer data for non-streamed audio! "+AL.GetErrorString(alError));
throw new Exception("Failed to set buffer data for non-streamed audio! "+Al.GetErrorString(alError));
}
MuffleBuffer(floatBuffer, SampleRate, reader.Channels);
CastBuffer(floatBuffer, shortBuffer, readSamples);
AL.BufferData((int)ALMuffledBuffer, ALFormat, shortBuffer,
Al.BufferData(ALMuffledBuffer, ALFormat, shortBuffer,
readSamples * sizeof(short), SampleRate);
alError = AL.GetError();
if (alError != ALError.NoError)
alError = Al.GetError();
if (alError != Al.NoError)
{
throw new Exception("Failed to set buffer data for non-streamed audio! " + AL.GetErrorString(alError));
throw new Exception("Failed to set buffer data for non-streamed audio! " + Al.GetErrorString(alError));
}
reader.Dispose();
@@ -98,4 +98,4 @@ namespace Barotrauma.Sounds
base.Dispose();
}
}
}
}
@@ -1,5 +1,5 @@
using System;
using OpenTK.Audio.OpenAL;
using OpenAL;
using Microsoft.Xna.Framework;
using System.IO;
@@ -57,7 +57,7 @@ namespace Barotrauma.Sounds
get { return !Stream ? alMuffledBuffer : 0; }
}
public ALFormat ALFormat
public int ALFormat
{
get;
protected set;
@@ -91,26 +91,26 @@ namespace Barotrauma.Sounds
if (!stream)
{
AL.GenBuffer(out alBuffer);
ALError alError = AL.GetError();
if (alError != ALError.NoError)
Al.GenBuffer(out alBuffer);
int alError = Al.GetError();
if (alError != Al.NoError)
{
throw new Exception("Failed to create OpenAL buffer for non-streamed sound: " + AL.GetErrorString(alError));
throw new Exception("Failed to create OpenAL buffer for non-streamed sound: " + Al.GetErrorString(alError));
}
if (!AL.IsBuffer(alBuffer))
if (!Al.IsBuffer(alBuffer))
{
throw new Exception("Generated OpenAL buffer is invalid!");
}
AL.GenBuffer(out alMuffledBuffer);
alError = AL.GetError();
if (alError != ALError.NoError)
Al.GenBuffer(out alMuffledBuffer);
alError = Al.GetError();
if (alError != Al.NoError)
{
throw new Exception("Failed to create OpenAL buffer for non-streamed sound: " + AL.GetErrorString(alError));
throw new Exception("Failed to create OpenAL buffer for non-streamed sound: " + Al.GetErrorString(alError));
}
if (!AL.IsBuffer(alMuffledBuffer))
if (!Al.IsBuffer(alMuffledBuffer))
{
throw new Exception("Generated OpenAL buffer is invalid!");
}
@@ -186,32 +186,32 @@ namespace Barotrauma.Sounds
Owner.KillChannels(this);
if (alBuffer != 0)
{
if (!AL.IsBuffer(alBuffer))
if (!Al.IsBuffer(alBuffer))
{
throw new Exception("Buffer to delete is invalid!");
}
AL.DeleteBuffer(ref alBuffer); alBuffer = 0;
Al.DeleteBuffer(alBuffer); alBuffer = 0;
ALError alError = AL.GetError();
if (alError != ALError.NoError)
int alError = Al.GetError();
if (alError != Al.NoError)
{
throw new Exception("Failed to delete OpenAL buffer for non-streamed sound: " + AL.GetErrorString(alError));
throw new Exception("Failed to delete OpenAL buffer for non-streamed sound: " + Al.GetErrorString(alError));
}
}
if (alMuffledBuffer != 0)
{
if (!AL.IsBuffer(alMuffledBuffer))
if (!Al.IsBuffer(alMuffledBuffer))
{
throw new Exception("Buffer to delete is invalid!");
}
AL.DeleteBuffer(ref alMuffledBuffer); alMuffledBuffer = 0;
Al.DeleteBuffer(alMuffledBuffer); alMuffledBuffer = 0;
ALError alError = AL.GetError();
if (alError != ALError.NoError)
int alError = Al.GetError();
if (alError != Al.NoError)
{
throw new Exception("Failed to delete OpenAL buffer for non-streamed sound: " + AL.GetErrorString(alError));
throw new Exception("Failed to delete OpenAL buffer for non-streamed sound: " + Al.GetErrorString(alError));
}
}
@@ -1,5 +1,5 @@
using System;
using OpenTK.Audio.OpenAL;
using OpenAL;
using Microsoft.Xna.Framework;
using System.Collections.Generic;
@@ -15,49 +15,49 @@ namespace Barotrauma.Sounds
public SoundSourcePool(int sourceCount = SoundManager.SOURCE_COUNT)
{
ALError alError = ALError.NoError;
int alError = Al.NoError;
ALSources = new uint[sourceCount];
for (int i = 0; i < sourceCount; i++)
{
AL.GenSource(out ALSources[i]);
alError = AL.GetError();
if (alError != ALError.NoError)
Al.GenSource(out ALSources[i]);
alError = Al.GetError();
if (alError != Al.NoError)
{
throw new Exception("Error generating alSource[" + i.ToString() + "]: " + AL.GetErrorString(alError));
throw new Exception("Error generating alSource[" + i.ToString() + "]: " + Al.GetErrorString(alError));
}
if (!AL.IsSource(ALSources[i]))
if (!Al.IsSource(ALSources[i]))
{
throw new Exception("Generated alSource[" + i.ToString() + "] is invalid!");
}
AL.SourceStop(ALSources[i]);
alError = AL.GetError();
if (alError != ALError.NoError)
Al.SourceStop(ALSources[i]);
alError = Al.GetError();
if (alError != Al.NoError)
{
throw new Exception("Error stopping newly generated alSource[" + i.ToString() + "]: " + AL.GetErrorString(alError));
throw new Exception("Error stopping newly generated alSource[" + i.ToString() + "]: " + Al.GetErrorString(alError));
}
AL.Source(ALSources[i], ALSourcef.MinGain, 0.0f);
alError = AL.GetError();
if (alError != ALError.NoError)
Al.Sourcef(ALSources[i], Al.MinGain, 0.0f);
alError = Al.GetError();
if (alError != Al.NoError)
{
throw new Exception("Error setting min gain: " + AL.GetErrorString(alError));
throw new Exception("Error setting min gain: " + Al.GetErrorString(alError));
}
AL.Source(ALSources[i], ALSourcef.MaxGain, 1.0f);
alError = AL.GetError();
if (alError != ALError.NoError)
Al.Sourcef(ALSources[i], Al.MaxGain, 1.0f);
alError = Al.GetError();
if (alError != Al.NoError)
{
throw new Exception("Error setting max gain: " + AL.GetErrorString(alError));
throw new Exception("Error setting max gain: " + Al.GetErrorString(alError));
}
AL.Source(ALSources[i], ALSourcef.RolloffFactor, 1.0f);
alError = AL.GetError();
if (alError != ALError.NoError)
Al.Sourcef(ALSources[i], Al.RolloffFactor, 1.0f);
alError = Al.GetError();
if (alError != Al.NoError)
{
throw new Exception("Error setting rolloff factor: " + AL.GetErrorString(alError));
throw new Exception("Error setting rolloff factor: " + Al.GetErrorString(alError));
}
}
}
@@ -66,11 +66,11 @@ namespace Barotrauma.Sounds
{
for (int i = 0; i < ALSources.Length; i++)
{
AL.DeleteSource(ref ALSources[i]);
ALError alError = AL.GetError();
if (alError != ALError.NoError)
Al.DeleteSource(ALSources[i]);
int alError = Al.GetError();
if (alError != Al.NoError)
{
throw new Exception("Failed to delete ALSources[" + i.ToString() + "]: " + AL.GetErrorString(alError));
throw new Exception("Failed to delete ALSources[" + i.ToString() + "]: " + Al.GetErrorString(alError));
}
}
ALSources = null;
@@ -95,35 +95,35 @@ namespace Barotrauma.Sounds
if (position != null)
{
uint alSource = Sound.Owner.GetSourceFromIndex(Sound.SourcePoolIndex, ALSourceIndex);
AL.Source(alSource, ALSourceb.SourceRelative, false);
ALError alError = AL.GetError();
if (alError != ALError.NoError)
Al.Sourcei(alSource, Al.SourceRelative, Al.False);
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: " + Al.GetErrorString(alError));
}
AL.Source(alSource, ALSource3f.Position, position.Value.X, position.Value.Y, position.Value.Z);
alError = AL.GetError();
if (alError != ALError.NoError)
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: " + Al.GetErrorString(alError));
}
}
else
{
uint alSource = Sound.Owner.GetSourceFromIndex(Sound.SourcePoolIndex, ALSourceIndex);
AL.Source(alSource, ALSourceb.SourceRelative, true);
ALError alError = AL.GetError();
if (alError != ALError.NoError)
Al.Sourcei(alSource, Al.SourceRelative, Al.True);
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: " + Al.GetErrorString(alError));
}
AL.Source(alSource, ALSource3f.Position, 0.0f, 0.0f, 0.0f);
alError = AL.GetError();
if (alError != ALError.NoError)
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: " + Al.GetErrorString(alError));
}
}
}
@@ -140,12 +140,12 @@ namespace Barotrauma.Sounds
if (ALSourceIndex < 0) return;
uint alSource = Sound.Owner.GetSourceFromIndex(Sound.SourcePoolIndex, ALSourceIndex);
AL.Source(alSource, ALSourcef.ReferenceDistance, near);
Al.Sourcef(alSource, Al.ReferenceDistance, near);
ALError alError = AL.GetError();
if (alError != ALError.NoError)
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: " + Al.GetErrorString(alError));
}
}
}
@@ -161,11 +161,11 @@ namespace Barotrauma.Sounds
if (ALSourceIndex < 0) return;
uint alSource = Sound.Owner.GetSourceFromIndex(Sound.SourcePoolIndex, ALSourceIndex);
AL.Source(alSource, ALSourcef.MaxDistance, far);
ALError alError = AL.GetError();
if (alError != ALError.NoError)
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: " + Al.GetErrorString(alError));
}
}
}
@@ -185,11 +185,11 @@ namespace Barotrauma.Sounds
float effectiveGain = gain;
if (category != null) effectiveGain *= Sound.Owner.GetCategoryGainMultiplier(category);
AL.Source(alSource, ALSourcef.Gain, effectiveGain);
ALError alError = AL.GetError();
if (alError != ALError.NoError)
Al.Sourcef(alSource, Al.Gain, effectiveGain);
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: " + Al.GetErrorString(alError));
}
}
}
@@ -207,11 +207,11 @@ namespace Barotrauma.Sounds
if (!IsStream)
{
uint alSource = Sound.Owner.GetSourceFromIndex(Sound.SourcePoolIndex, ALSourceIndex);
AL.Source(alSource, ALSourceb.Looping, looping);
ALError alError = AL.GetError();
if (alError != ALError.NoError)
Al.Sourcei(alSource, Al.Looping, looping ? Al.True : Al.False);
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: " + Al.GetErrorString(alError));
}
}
}
@@ -242,41 +242,41 @@ namespace Barotrauma.Sounds
if (!IsStream)
{
uint alSource = Sound.Owner.GetSourceFromIndex(Sound.SourcePoolIndex, ALSourceIndex);
int playbackPos; AL.GetSource(alSource, ALGetSourcei.SampleOffset, out playbackPos);
ALError alError = AL.GetError();
if (alError != ALError.NoError)
int playbackPos; Al.GetSourcei(alSource, Al.SampleOffset, out playbackPos);
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: " + Al.GetErrorString(alError));
}
AL.SourceStop(alSource);
Al.SourceStop(alSource);
alError = AL.GetError();
if (alError != ALError.NoError)
alError = Al.GetError();
if (alError != Al.NoError)
{
throw new Exception("Failed to stop source: " + AL.GetErrorString(alError));
throw new Exception("Failed to stop source: " + Al.GetErrorString(alError));
}
AL.BindBufferToSource(alSource,(uint)(muffled ? Sound.ALMuffledBuffer : Sound.ALBuffer));
Al.Sourcei(alSource, Al.Buffer, muffled ? (int)Sound.ALMuffledBuffer : (int)Sound.ALBuffer);
alError = AL.GetError();
if (alError != ALError.NoError)
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: " + Al.GetErrorString(alError));
}
AL.SourcePlay(alSource);
alError = AL.GetError();
if (alError != ALError.NoError)
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: " + Al.GetErrorString(alError));
}
AL.Source(alSource, ALSourcei.SampleOffset, playbackPos);
alError = AL.GetError();
if (alError != ALError.NoError)
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: " + Al.GetErrorString(alError));
}
}
}
@@ -324,11 +324,13 @@ namespace Barotrauma.Sounds
{
if (ALSourceIndex < 0) return false;
if (IsStream && !reachedEndSample) return true;
bool playing = AL.GetSourceState(Sound.Owner.GetSourceFromIndex(Sound.SourcePoolIndex, ALSourceIndex)) == ALSourceState.Playing;
ALError alError = AL.GetError();
if (alError != ALError.NoError)
int state;
Al.GetSourcei(Sound.Owner.GetSourceFromIndex(Sound.SourcePoolIndex, ALSourceIndex), Al.SourceState, out state);
bool playing = state == Al.Playing;
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: " + Al.GetErrorString(alError));
}
return playing;
}
@@ -357,47 +359,47 @@ namespace Barotrauma.Sounds
{
if (!IsStream)
{
AL.BindBufferToSource(sound.Owner.GetSourceFromIndex(Sound.SourcePoolIndex, ALSourceIndex), 0);
ALError alError = AL.GetError();
if (alError != ALError.NoError)
Al.Sourcei(sound.Owner.GetSourceFromIndex(Sound.SourcePoolIndex, ALSourceIndex), Al.Buffer, 0);
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: " + Al.GetErrorString(alError));
}
if (!AL.IsBuffer(sound.ALBuffer))
if (!Al.IsBuffer(sound.ALBuffer))
{
throw new Exception(sound.Filename + " has an invalid buffer!");
}
uint alBuffer = sound.Owner.GetCategoryMuffle(category) || muffle ? sound.ALMuffledBuffer : sound.ALBuffer;
AL.BindBufferToSource(sound.Owner.GetSourceFromIndex(Sound.SourcePoolIndex, ALSourceIndex), alBuffer);
alError = AL.GetError();
if (alError != ALError.NoError)
Al.Sourcei(sound.Owner.GetSourceFromIndex(Sound.SourcePoolIndex, ALSourceIndex), Al.Buffer, (int)alBuffer);
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() + "): " + Al.GetErrorString(alError));
}
AL.SourcePlay(sound.Owner.GetSourceFromIndex(Sound.SourcePoolIndex, ALSourceIndex));
alError = AL.GetError();
if (alError != ALError.NoError)
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: " + Al.GetErrorString(alError));
}
}
else
{
AL.BindBufferToSource(sound.Owner.GetSourceFromIndex(Sound.SourcePoolIndex, ALSourceIndex), (uint)sound.ALBuffer);
ALError alError = AL.GetError();
if (alError != ALError.NoError)
Al.Sourcei(sound.Owner.GetSourceFromIndex(Sound.SourcePoolIndex, ALSourceIndex), Al.Buffer, (int)sound.ALBuffer);
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: " + Al.GetErrorString(alError));
}
AL.Source(sound.Owner.GetSourceFromIndex(Sound.SourcePoolIndex, ALSourceIndex), ALSourceb.Looping, false);
alError = AL.GetError();
if (alError != ALError.NoError)
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: " + Al.GetErrorString(alError));
}
streamShortBuffer = new short[STREAM_BUFFER_SIZE];
@@ -406,15 +408,15 @@ namespace Barotrauma.Sounds
emptyBuffers = new List<uint>();
for (int i = 0; i < 4; i++)
{
AL.GenBuffer(out streamBuffers[i]);
Al.GenBuffer(out streamBuffers[i]);
alError = AL.GetError();
if (alError != ALError.NoError)
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: " + Al.GetErrorString(alError));
}
if (!AL.IsBuffer(streamBuffers[i]))
if (!Al.IsBuffer(streamBuffers[i]))
{
throw new Exception("Generated streamBuffer[" + i.ToString() + "] is invalid!");
}
@@ -445,57 +447,57 @@ namespace Barotrauma.Sounds
{
if (ALSourceIndex >= 0)
{
AL.SourceStop(Sound.Owner.GetSourceFromIndex(Sound.SourcePoolIndex, ALSourceIndex));
ALError alError = AL.GetError();
if (alError != ALError.NoError)
Al.SourceStop(Sound.Owner.GetSourceFromIndex(Sound.SourcePoolIndex, ALSourceIndex));
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: " + Al.GetErrorString(alError));
}
if (IsStream)
{
uint alSource = Sound.Owner.GetSourceFromIndex(Sound.SourcePoolIndex, ALSourceIndex);
AL.SourceStop(alSource);
alError = AL.GetError();
if (alError != ALError.NoError)
Al.SourceStop(alSource);
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: " + Al.GetErrorString(alError));
}
int buffersToUnqueue = 0;
int[] unqueuedBuffers = null;
uint[] unqueuedBuffers = null;
buffersToUnqueue = 0;
AL.GetSource(alSource, ALGetSourcei.BuffersProcessed, out buffersToUnqueue);
alError = AL.GetError();
if (alError != ALError.NoError)
Al.GetSourcei(alSource, Al.BuffersProcessed, out buffersToUnqueue);
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: " + Al.GetErrorString(alError));
}
unqueuedBuffers = new int[buffersToUnqueue];
AL.SourceUnqueueBuffers((int)alSource, buffersToUnqueue, unqueuedBuffers);
alError = AL.GetError();
if (alError != ALError.NoError)
unqueuedBuffers = new uint[buffersToUnqueue];
Al.SourceUnqueueBuffers(alSource, buffersToUnqueue, 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: " + Al.GetErrorString(alError));
}
AL.BindBufferToSource(alSource, 0);
alError = AL.GetError();
if (alError != ALError.NoError)
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: " + Al.GetErrorString(alError));
}
for (int i = 0; i < 4; i++)
{
AL.DeleteBuffer(ref streamBuffers[i]);
alError = AL.GetError();
if (alError != ALError.NoError)
Al.DeleteBuffer(streamBuffers[i]);
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()+"): " + Al.GetErrorString(alError));
}
}
@@ -503,11 +505,11 @@ namespace Barotrauma.Sounds
}
else
{
AL.BindBufferToSource(Sound.Owner.GetSourceFromIndex(Sound.SourcePoolIndex, ALSourceIndex), 0);
alError = AL.GetError();
if (alError != ALError.NoError)
Al.Sourcei(Sound.Owner.GetSourceFromIndex(Sound.SourcePoolIndex, ALSourceIndex), Al.Buffer, 0);
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: " + Al.GetErrorString(alError));
}
}
@@ -526,47 +528,49 @@ namespace Barotrauma.Sounds
{
uint alSource = Sound.Owner.GetSourceFromIndex(Sound.SourcePoolIndex, ALSourceIndex);
bool playing = AL.GetSourceState(alSource) == ALSourceState.Playing;
ALError alError = AL.GetError();
if (alError != ALError.NoError)
int state;
Al.GetSourcei(Sound.Owner.GetSourceFromIndex(Sound.SourcePoolIndex, ALSourceIndex), Al.SourceState, out state);
bool playing = state == Al.Playing;
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: " + Al.GetErrorString(alError));
}
int buffersToUnqueue = 0;
int[] unqueuedBuffers = null;
uint[] unqueuedBuffers = null;
if (!startedPlaying)
{
buffersToUnqueue = 0;
AL.GetSource(alSource, ALGetSourcei.BuffersProcessed, out buffersToUnqueue);
alError = AL.GetError();
if (alError != ALError.NoError)
Al.GetSourcei(alSource, Al.BuffersProcessed, out buffersToUnqueue);
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: " + Al.GetErrorString(alError));
}
unqueuedBuffers = new int[buffersToUnqueue+emptyBuffers.Count];
AL.SourceUnqueueBuffers((int)alSource, buffersToUnqueue, unqueuedBuffers);
unqueuedBuffers = new uint[buffersToUnqueue+emptyBuffers.Count];
Al.SourceUnqueueBuffers(alSource, buffersToUnqueue, unqueuedBuffers);
for (int i = 0; i < emptyBuffers.Count; i++)
{
unqueuedBuffers[buffersToUnqueue + i] = (int)emptyBuffers[i];
unqueuedBuffers[buffersToUnqueue + i] = emptyBuffers[i];
}
buffersToUnqueue += emptyBuffers.Count;
emptyBuffers.Clear();
alError = AL.GetError();
if (alError != ALError.NoError)
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: " + Al.GetErrorString(alError));
}
}
else
{
startedPlaying = false;
buffersToUnqueue = 4;
unqueuedBuffers = new int[4];
unqueuedBuffers = new uint[4];
for (int i = 0; i < 4; i++)
{
unqueuedBuffers[i] = (int)streamBuffers[i];
unqueuedBuffers[i] = streamBuffers[i];
}
}
@@ -612,20 +616,20 @@ namespace Barotrauma.Sounds
if (readSamples > 0)
{
AL.BufferData<short>(unqueuedBuffers[i], Sound.ALFormat, buffer, readSamples, Sound.SampleRate);
Al.BufferData<short>(unqueuedBuffers[i], Sound.ALFormat, buffer, readSamples, Sound.SampleRate);
alError = AL.GetError();
if (alError != ALError.NoError)
alError = Al.GetError();
if (alError != Al.NoError)
{
throw new Exception("Failed to assign data to stream buffer: " +
AL.GetErrorString(alError) + ": " + unqueuedBuffers[i].ToString() + "/" + unqueuedBuffers.Length + ", readSamples: " + readSamples);
Al.GetErrorString(alError) + ": " + unqueuedBuffers[i].ToString() + "/" + unqueuedBuffers.Length + ", readSamples: " + readSamples);
}
AL.SourceQueueBuffer((int)alSource, unqueuedBuffers[i]);
alError = AL.GetError();
if (alError != ALError.NoError)
Al.SourceQueueBuffer(alSource, unqueuedBuffers[i]);
alError = Al.GetError();
if (alError != Al.NoError)
{
throw new Exception("Failed to queue buffer[" + i.ToString() + "] to stream: " + AL.GetErrorString(alError));
throw new Exception("Failed to queue buffer[" + i.ToString() + "] to stream: " + Al.GetErrorString(alError));
}
}
else if (readSamples < 0)
@@ -637,10 +641,11 @@ namespace Barotrauma.Sounds
emptyBuffers.Add((uint)unqueuedBuffers[i]);
}
}
if (AL.GetSourceState(alSource) != ALSourceState.Playing)
Al.GetSourcei(alSource, Al.SourceState, out state);
if (state != Al.Playing)
{
AL.SourcePlay(alSource);
Al.SourcePlay(alSource);
}
}
}
@@ -2,7 +2,7 @@
using System.Threading;
using System.Collections.Generic;
using System.Xml.Linq;
using OpenTK.Audio.OpenAL;
using OpenAL;
using Microsoft.Xna.Framework;
using System.Linq;
using System.IO;
@@ -20,7 +20,7 @@ namespace Barotrauma.Sounds
}
private IntPtr alcDevice;
private OpenTK.ContextHandle alcContext;
private IntPtr alcContext;
public enum SourcePoolIndex
{
@@ -42,11 +42,11 @@ namespace Barotrauma.Sounds
{
if (Disabled) { return; }
listenerPosition = value;
AL.Listener(ALListener3f.Position,value.X,value.Y,value.Z);
ALError alError = AL.GetError();
if (alError != ALError.NoError)
Al.Listener3f(Al.Position,value.X,value.Y,value.Z);
int alError = Al.GetError();
if (alError != Al.NoError)
{
throw new Exception("Failed to set listener position: " + AL.GetErrorString(alError));
throw new Exception("Failed to set listener position: " + Al.GetErrorString(alError));
}
}
}
@@ -59,11 +59,11 @@ namespace Barotrauma.Sounds
{
if (Disabled) { return; }
listenerOrientation[0] = value.X; listenerOrientation[1] = value.Y; listenerOrientation[2] = value.Z;
AL.Listener(ALListenerfv.Orientation, ref listenerOrientation);
ALError alError = AL.GetError();
if (alError != ALError.NoError)
Al.Listenerfv(Al.Orientation, listenerOrientation);
int alError = Al.GetError();
if (alError != Al.NoError)
{
throw new Exception("Failed to set listener target vector: " + AL.GetErrorString(alError));
throw new Exception("Failed to set listener target vector: " + Al.GetErrorString(alError));
}
}
}
@@ -74,11 +74,11 @@ namespace Barotrauma.Sounds
{
if (Disabled) { return; }
listenerOrientation[3] = value.X; listenerOrientation[4] = value.Y; listenerOrientation[5] = value.Z;
AL.Listener(ALListenerfv.Orientation, ref listenerOrientation);
ALError alError = AL.GetError();
if (alError != ALError.NoError)
Al.Listenerfv(Al.Orientation, listenerOrientation);
int alError = Al.GetError();
if (alError != Al.NoError)
{
throw new Exception("Failed to set listener up vector: " + AL.GetErrorString(alError));
throw new Exception("Failed to set listener up vector: " + Al.GetErrorString(alError));
}
}
}
@@ -92,11 +92,11 @@ namespace Barotrauma.Sounds
if (Disabled) { return; }
if (Math.Abs(ListenerGain - value) < 0.001f) { return; }
listenerGain = value;
AL.Listener(ALListenerf.Gain, listenerGain);
ALError alError = AL.GetError();
if (alError != ALError.NoError)
Al.Listenerf(Al.Gain, listenerGain);
int alError = Al.GetError();
if (alError != Al.NoError)
{
throw new Exception("Failed to set listener gain: " + AL.GetErrorString(alError));
throw new Exception("Failed to set listener gain: " + Al.GetErrorString(alError));
}
}
}
@@ -126,8 +126,8 @@ namespace Barotrauma.Sounds
return;
}
AlcError alcError = Alc.GetError(alcDevice);
if (alcError != AlcError.NoError)
int alcError = Alc.GetError(alcDevice);
if (alcError != Alc.NoError)
{
//The audio device probably wasn't ready, this happens quite often
//Just wait a while and try again
@@ -136,7 +136,7 @@ namespace Barotrauma.Sounds
alcDevice = Alc.OpenDevice(null);
alcError = Alc.GetError(alcDevice);
if (alcError != AlcError.NoError)
if (alcError != Alc.NoError)
{
DebugConsole.ThrowError("Error initializing ALC device: " + alcError.ToString() + ". Disabling audio playback...");
Disabled = true;
@@ -161,14 +161,14 @@ namespace Barotrauma.Sounds
}
alcError = Alc.GetError(alcDevice);
if (alcError != AlcError.NoError)
if (alcError != Alc.NoError)
{
DebugConsole.ThrowError("Error after assigning ALC context: " + alcError.ToString() + ". Disabling audio playback...");
Disabled = true;
return;
}
ALError alError = ALError.NoError;
int alError = Al.NoError;
sourcePools = new SoundSourcePool[2];
sourcePools[(int)SourcePoolIndex.Default] = new SoundSourcePool(SOURCE_COUNT);
@@ -177,12 +177,12 @@ namespace Barotrauma.Sounds
sourcePools[(int)SourcePoolIndex.Voice] = new SoundSourcePool(8);
playingChannels[(int)SourcePoolIndex.Voice] = new SoundChannel[8];
AL.DistanceModel(ALDistanceModel.LinearDistanceClamped);
Al.DistanceModel(Al.LinearDistanceClamped);
alError = AL.GetError();
if (alError != ALError.NoError)
alError = Al.GetError();
if (alError != Al.NoError)
{
DebugConsole.ThrowError("Error setting distance model: " + AL.GetErrorString(alError) + ". Disabling audio playback...");
DebugConsole.ThrowError("Error setting distance model: " + Al.GetErrorString(alError) + ". Disabling audio playback...");
Disabled = true;
return;
}
@@ -239,7 +239,7 @@ namespace Barotrauma.Sounds
{
if (Disabled || srcInd < 0 || srcInd >= sourcePools[(int)poolIndex].ALSources.Length) return 0;
if (!AL.IsSource(sourcePools[(int)poolIndex].ALSources[srcInd]))
if (!Al.IsSource(sourcePools[(int)poolIndex].ALSources[srcInd]))
{
throw new Exception("alSources[" + srcInd.ToString() + "] is invalid!");
}
@@ -276,8 +276,8 @@ namespace Barotrauma.Sounds
{
for (int i = 0; i < sourcePools[0].ALSources.Length; i++)
{
AL.Source(sourcePools[0].ALSources[i], ALSourcef.MaxGain, i == ind ? 1.0f : 0.0f);
AL.Source(sourcePools[0].ALSources[i], ALSourcef.MinGain, 0.0f);
Al.Sourcef(sourcePools[0].ALSources[i], Al.MaxGain, i == ind ? 1.0f : 0.0f);
Al.Sourcef(sourcePools[0].ALSources[i], Al.MinGain, 0.0f);
}
}
#endif
@@ -503,10 +503,7 @@ namespace Barotrauma.Sounds
}
}
}
if (streamingThread != null && !streamingThread.ThreadState.HasFlag(ThreadState.Stopped))
{
streamingThread.Join();
}
streamingThread?.Join();
for (int i = loadedSounds.Count - 1; i >= 0; i--)
{
loadedSounds[i].Dispose();
@@ -514,7 +511,7 @@ namespace Barotrauma.Sounds
sourcePools[(int)SourcePoolIndex.Default]?.Dispose();
sourcePools[(int)SourcePoolIndex.Voice]?.Dispose();
if (!Alc.MakeContextCurrent(OpenTK.ContextHandle.Zero))
if (!Alc.MakeContextCurrent(IntPtr.Zero))
{
throw new Exception("Failed to detach the current ALC context! (error code: " + Alc.GetError(alcDevice).ToString() + ")");
}
@@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenTK.Audio.OpenAL;
using OpenAL;
using Microsoft.Xna.Framework;
using System.Runtime.InteropServices;
using System.Threading;
@@ -21,7 +21,7 @@ namespace Barotrauma.Sounds
public VideoSound(SoundManager owner, string filename, int sampleRate, Video vid) : base(owner, filename, true, false)
{
ALFormat = ALFormat.Stereo16;
ALFormat = Al.FormatStereo16;
SampleRate = sampleRate;
sampleQueue = new Queue<short[]>();
@@ -110,4 +110,4 @@ namespace Barotrauma.Sounds
}
}
}
}
}
@@ -1,6 +1,6 @@
using Barotrauma.Networking;
using Microsoft.Xna.Framework;
using OpenTK.Audio.OpenAL;
using OpenAL;
using System;
using System.Collections.Generic;
@@ -58,7 +58,7 @@ namespace Barotrauma.Sounds
{
VoipConfig.SetupEncoding();
ALFormat = ALFormat.Mono16;
ALFormat = Al.FormatMono16;
SampleRate = VoipConfig.FREQUENCY;
queue = q;