(5a377a8ee) Unstable v0.9.1000.0

This commit is contained in:
Juan Pablo Arce
2020-05-13 12:55:42 -03:00
parent b143329701
commit a1ca41aa5d
426 changed files with 14384 additions and 5708 deletions
@@ -44,13 +44,15 @@ namespace Barotrauma.Sounds
new BandpassFilter(VoipConfig.FREQUENCY, 2000)
};
private float gain;
public float Gain
{
get { return soundChannel == null ? 0.0f : soundChannel.Gain; }
get { return soundChannel == null ? 0.0f : gain; }
set
{
if (soundChannel == null) { return; }
soundChannel.Gain = value;
gain = value;
soundChannel.Gain = value * GameMain.Config.VoiceChatVolume;
}
}
@@ -75,6 +77,7 @@ namespace Barotrauma.Sounds
SoundChannel chn = new SoundChannel(this, 1.0f, null, 0.4f, 1.0f, "voip", false);
soundChannel = chn;
Gain = 1.0f;
}
public override float GetAmplitudeAtPlaybackPos(int playbackPos)
@@ -98,6 +101,12 @@ namespace Barotrauma.Sounds
for (int i = 0; i < readSamples; i++)
{
float fVal = ShortToFloat(buffer[i]);
if (gain * GameMain.Config.VoiceChatVolume > 1.0f) //TODO: take distance into account?
{
fVal = Math.Clamp(fVal * gain * GameMain.Config.VoiceChatVolume, -1.0f, 1.0f);
}
if (UseMuffleFilter)
{
foreach (var filter in muffleFilters)
@@ -114,19 +123,6 @@ namespace Barotrauma.Sounds
}
buffer[i] = FloatToShort(fVal);
}
if (UseMuffleFilter)
{
ApplyFilters(muffleFilters, buffer, readSamples);
}
if (UseRadioFilter)
{
ApplyFilters(radioFilters, buffer, readSamples);
}
}
private void ApplyFilters(IEnumerable<BiQuad> filters, short[] buffer, int readSamples)
{
}
public override SoundChannel Play(float gain, float range, Vector2 position, bool muffle = false)
@@ -152,13 +148,21 @@ namespace Barotrauma.Sounds
public override int FillStreamBuffer(int samplePos, short[] buffer)
{
queue.RetrieveBuffer(bufferID, out int compressedSize, out byte[] compressedBuffer);
if (compressedSize > 0)
try
{
VoipConfig.Decoder.Decode(compressedBuffer, 0, compressedSize, buffer, 0, VoipConfig.BUFFER_SIZE);
bufferID++;
return VoipConfig.BUFFER_SIZE * 2;
if (compressedSize > 0)
{
VoipConfig.Decoder.Decode(compressedBuffer, 0, compressedSize, buffer, 0, VoipConfig.BUFFER_SIZE);
bufferID++;
return VoipConfig.BUFFER_SIZE * 2;
}
if (bufferID < queue.LatestBufferID - (VoipQueue.BUFFER_COUNT - 1)) bufferID = queue.LatestBufferID - (VoipQueue.BUFFER_COUNT - 1);
}
catch (Exception e)
{
DebugConsole.ThrowError($"Failed to decode Opus buffer (buffer size {compressedBuffer.Length}, packet size {compressedSize})", e);
bufferID = queue.LatestBufferID - (VoipQueue.BUFFER_COUNT - 1);
}
if (bufferID < queue.LatestBufferID - (VoipQueue.BUFFER_COUNT - 1)) bufferID = queue.LatestBufferID - (VoipQueue.BUFFER_COUNT - 1);
return 0;
}