Build 0.20.7.0
This commit is contained in:
@@ -11,7 +11,7 @@ namespace Barotrauma.Sounds
|
||||
private VorbisReader reader;
|
||||
|
||||
//key = sample rate, value = filter
|
||||
private static Dictionary<int, BiQuad> muffleFilters = new Dictionary<int, BiQuad>();
|
||||
private static readonly Dictionary<int, BiQuad> muffleFilters = new Dictionary<int, BiQuad>();
|
||||
|
||||
private static List<float> playbackAmplitude;
|
||||
private const int AMPLITUDE_SAMPLE_COUNT = 4410; //100ms in a 44100hz file
|
||||
@@ -29,8 +29,8 @@ namespace Barotrauma.Sounds
|
||||
|
||||
public override int FillStreamBuffer(int samplePos, short[] buffer)
|
||||
{
|
||||
if (!Stream) throw new Exception("Called FillStreamBuffer on a non-streamed sound!");
|
||||
if (reader == null) throw new Exception("Called FillStreamBuffer when the reader is null!");
|
||||
if (!Stream) { throw new Exception("Called FillStreamBuffer on a non-streamed sound!"); }
|
||||
if (reader == null) { throw new Exception("Called FillStreamBuffer when the reader is null!"); }
|
||||
|
||||
if (samplePos >= reader.TotalSamples * reader.Channels * 2) return 0;
|
||||
|
||||
|
||||
@@ -24,11 +24,12 @@ namespace Barotrauma.Sounds
|
||||
|
||||
public readonly bool StreamsReliably;
|
||||
|
||||
private readonly SoundManager.SourcePoolIndex sourcePoolIndex = SoundManager.SourcePoolIndex.Default;
|
||||
public virtual SoundManager.SourcePoolIndex SourcePoolIndex
|
||||
{
|
||||
get
|
||||
{
|
||||
return SoundManager.SourcePoolIndex.Default;
|
||||
return sourcePoolIndex;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,13 +60,14 @@ namespace Barotrauma.Sounds
|
||||
public float BaseNear;
|
||||
public float BaseFar;
|
||||
|
||||
public Sound(SoundManager owner, string filename, bool stream, bool streamsReliably, XElement xElement=null, bool getFullPath=true)
|
||||
public Sound(SoundManager owner, string filename, bool stream, bool streamsReliably, XElement xElement = null, bool getFullPath = true)
|
||||
{
|
||||
Owner = owner;
|
||||
Filename = getFullPath ? Path.GetFullPath(filename.CleanUpPath()).CleanUpPath() : filename;
|
||||
Stream = stream;
|
||||
StreamsReliably = streamsReliably;
|
||||
XElement = xElement;
|
||||
sourcePoolIndex = XElement.GetAttributeEnum("sourcepool", SoundManager.SourcePoolIndex.Default);
|
||||
|
||||
BaseGain = 1.0f;
|
||||
BaseNear = 100.0f;
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
using System;
|
||||
using Microsoft.Xna.Framework;
|
||||
using OpenAL;
|
||||
using Microsoft.Xna.Framework;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Barotrauma.Sounds
|
||||
{
|
||||
@@ -17,7 +15,7 @@ namespace Barotrauma.Sounds
|
||||
|
||||
public SoundSourcePool(int sourceCount = SoundManager.SOURCE_COUNT)
|
||||
{
|
||||
int alError = Al.NoError;
|
||||
int alError;
|
||||
|
||||
ALSources = new uint[sourceCount];
|
||||
for (int i = 0; i < sourceCount; i++)
|
||||
@@ -83,7 +81,7 @@ namespace Barotrauma.Sounds
|
||||
class SoundChannel : IDisposable
|
||||
{
|
||||
private const int STREAM_BUFFER_SIZE = 8820;
|
||||
private short[] streamShortBuffer;
|
||||
private readonly short[] streamShortBuffer;
|
||||
|
||||
private string debugName = "SoundChannel";
|
||||
|
||||
@@ -312,12 +310,12 @@ namespace Barotrauma.Sounds
|
||||
|
||||
if (ALSourceIndex < 0) { return; }
|
||||
|
||||
if (!IsPlaying) return;
|
||||
if (!IsPlaying) { return; }
|
||||
|
||||
if (!IsStream)
|
||||
{
|
||||
uint alSource = Sound.Owner.GetSourceFromIndex(Sound.SourcePoolIndex, ALSourceIndex);
|
||||
int playbackPos; Al.GetSourcei(alSource, Al.SampleOffset, out playbackPos);
|
||||
Al.GetSourcei(alSource, Al.SampleOffset, out int playbackPos);
|
||||
int alError = Al.GetError();
|
||||
if (alError != Al.NoError)
|
||||
{
|
||||
@@ -379,7 +377,7 @@ namespace Barotrauma.Sounds
|
||||
|
||||
if (!IsStream)
|
||||
{
|
||||
int playbackPos; Al.GetSourcei(alSource, Al.SampleOffset, out playbackPos);
|
||||
Al.GetSourcei(alSource, Al.SampleOffset, out int playbackPos);
|
||||
int alError = Al.GetError();
|
||||
if (alError != Al.NoError)
|
||||
{
|
||||
@@ -390,7 +388,7 @@ namespace Barotrauma.Sounds
|
||||
}
|
||||
else
|
||||
{
|
||||
float retVal = -1.0f;
|
||||
float retVal;
|
||||
Monitor.Enter(mutex);
|
||||
retVal = streamAmplitude;
|
||||
Monitor.Exit(mutex);
|
||||
@@ -432,8 +430,8 @@ namespace Barotrauma.Sounds
|
||||
private bool reachedEndSample;
|
||||
private int queueStartIndex;
|
||||
private readonly uint[] streamBuffers;
|
||||
private uint[] unqueuedBuffers;
|
||||
private float[] streamBufferAmplitudes;
|
||||
private readonly uint[] unqueuedBuffers;
|
||||
private readonly float[] streamBufferAmplitudes;
|
||||
|
||||
public int StreamSeekPos
|
||||
{
|
||||
@@ -448,18 +446,17 @@ namespace Barotrauma.Sounds
|
||||
}
|
||||
}
|
||||
|
||||
private object mutex;
|
||||
private readonly object mutex;
|
||||
|
||||
public bool IsPlaying
|
||||
{
|
||||
get
|
||||
{
|
||||
if (ALSourceIndex < 0) return false;
|
||||
if (IsStream && !reachedEndSample) return true;
|
||||
int state;
|
||||
if (ALSourceIndex < 0) { return false; }
|
||||
if (IsStream && !reachedEndSample) { return true; }
|
||||
uint alSource = Sound.Owner.GetSourceFromIndex(Sound.SourcePoolIndex, ALSourceIndex);
|
||||
if (!Al.IsSource(alSource)) return false;
|
||||
Al.GetSourcei(alSource, Al.SourceState, out state);
|
||||
if (!Al.IsSource(alSource)) { return false; }
|
||||
Al.GetSourcei(alSource, Al.SourceState, out int state);
|
||||
int alError = Al.GetError();
|
||||
if (alError != Al.NoError)
|
||||
{
|
||||
@@ -710,8 +707,7 @@ namespace Barotrauma.Sounds
|
||||
{
|
||||
uint alSource = Sound.Owner.GetSourceFromIndex(Sound.SourcePoolIndex, ALSourceIndex);
|
||||
|
||||
int state;
|
||||
Al.GetSourcei(alSource, Al.SourceState, out state);
|
||||
Al.GetSourcei(alSource, Al.SourceState, out int state);
|
||||
bool playing = state == Al.Playing;
|
||||
int alError = Al.GetError();
|
||||
if (alError != Al.NoError)
|
||||
@@ -719,8 +715,7 @@ namespace Barotrauma.Sounds
|
||||
throw new Exception("Failed to determine playing state from streamed source: " + debugName + ", " + Al.GetErrorString(alError));
|
||||
}
|
||||
|
||||
int unqueuedBufferCount;
|
||||
Al.GetSourcei(alSource, Al.BuffersProcessed, out unqueuedBufferCount);
|
||||
Al.GetSourcei(alSource, Al.BuffersProcessed, out int unqueuedBufferCount);
|
||||
alError = Al.GetError();
|
||||
if (alError != Al.NoError)
|
||||
{
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
using Barotrauma.IO;
|
||||
using Barotrauma.Networking;
|
||||
using Barotrauma.Networking;
|
||||
using Concentus.Structs;
|
||||
using Microsoft.Xna.Framework;
|
||||
using OpenAL;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Barotrauma.Sounds
|
||||
{
|
||||
@@ -26,12 +24,12 @@ namespace Barotrauma.Sounds
|
||||
}
|
||||
}
|
||||
|
||||
private VoipQueue queue;
|
||||
private readonly VoipQueue queue;
|
||||
private int bufferID = 0;
|
||||
|
||||
private SoundChannel soundChannel;
|
||||
|
||||
private OpusDecoder decoder;
|
||||
private readonly OpusDecoder decoder;
|
||||
|
||||
public bool UseRadioFilter;
|
||||
public bool UseMuffleFilter;
|
||||
@@ -39,11 +37,11 @@ namespace Barotrauma.Sounds
|
||||
public float Near { get; private set; }
|
||||
public float Far { get; private set; }
|
||||
|
||||
private BiQuad[] muffleFilters = new BiQuad[]
|
||||
private readonly BiQuad[] muffleFilters = new BiQuad[]
|
||||
{
|
||||
new LowpassFilter(VoipConfig.FREQUENCY, 800)
|
||||
};
|
||||
private BiQuad[] radioFilters = new BiQuad[]
|
||||
private readonly BiQuad[] radioFilters = new BiQuad[]
|
||||
{
|
||||
new BandpassFilter(VoipConfig.FREQUENCY, 2000)
|
||||
};
|
||||
@@ -101,13 +99,14 @@ namespace Barotrauma.Sounds
|
||||
|
||||
public void ApplyFilters(short[] buffer, int readSamples)
|
||||
{
|
||||
float finalGain = gain * GameSettings.CurrentConfig.Audio.VoiceChatVolume;
|
||||
for (int i = 0; i < readSamples; i++)
|
||||
{
|
||||
float fVal = ShortToFloat(buffer[i]);
|
||||
|
||||
if (gain * GameSettings.CurrentConfig.Audio.VoiceChatVolume > 1.0f) //TODO: take distance into account?
|
||||
if (finalGain > 1.0f) //TODO: take distance into account?
|
||||
{
|
||||
fVal = Math.Clamp(fVal * gain * GameSettings.CurrentConfig.Audio.VoiceChatVolume, -1f, 1f);
|
||||
fVal = Math.Clamp(fVal * finalGain, -1f, 1f);
|
||||
}
|
||||
|
||||
if (UseMuffleFilter)
|
||||
|
||||
Reference in New Issue
Block a user