2 using Concentus.Structs;
3 using Microsoft.Xna.Framework;
23 return soundChannel !=
null && soundChannel.
IsPlaying;
28 private int bufferID = 0;
32 private readonly OpusDecoder decoder;
39 public float Near {
get;
private set; }
40 public float Far {
get;
private set; }
46 private readonly BiQuad[] radioFilters =
new BiQuad[]
48 new BandpassFilter(VoipConfig.FREQUENCY, 2000)
50 private const float PostRadioFilterBoost = 1.2f;
55 get {
return soundChannel ==
null ? 0.0f : gain; }
58 if (soundChannel ==
null) {
return; }
60 soundChannel.
Gain = value * GameSettings.CurrentConfig.Audio.VoiceChatVolume * client.
VoiceVolume;
73 client = targetClient;
74 decoder = VoipConfig.CreateDecoder();
91 throw new NotImplementedException();
102 soundChannel.
Far =
Far = far;
107 float finalGain = gain * GameSettings.CurrentConfig.Audio.VoiceChatVolume * client.
VoiceVolume;
108 for (
int i = 0; i < readSamples; i++)
110 float fVal = ToolBox.ShortAudioSampleToFloat(buffer[i]);
112 if (finalGain > 1.0f)
114 fVal = Math.Clamp(fVal * finalGain, -1f, 1f);
119 foreach (var filter
in muffleFilters)
121 fVal = filter.Process(fVal);
126 foreach (var filter
in radioFilters)
128 fVal = Math.Clamp(filter.Process(fVal) * PostRadioFilterBoost, -1f, 1f);
131 buffer[i] = ToolBox.FloatToShortAudioSample(fVal);
135 public override SoundChannel Play(
float gain,
float range, Vector2 position,
bool muffle =
false)
137 throw new InvalidOperationException();
140 public override SoundChannel Play(Vector3? position,
float gain,
float freqMult = 1.0f,
bool muffle =
false)
142 throw new InvalidOperationException();
147 throw new InvalidOperationException();
152 throw new InvalidOperationException();
157 queue.RetrieveBuffer(bufferID, out
int compressedSize, out
byte[] compressedBuffer);
160 if (compressedSize > 0)
162 decoder.Decode(compressedBuffer, 0, compressedSize, buffer, 0, VoipConfig.BUFFER_SIZE);
164 return VoipConfig.BUFFER_SIZE;
170 DebugConsole.ThrowError($
"Failed to decode Opus buffer (buffer size {compressedBuffer.Length}, packet size {compressedSize})", e);
179 if (soundChannel !=
null)
Represents a biquad-filter.
Used to apply a lowpass-filter to a signal.
float???? CurrentAmplitude
void SetRange(float near, float far)
void ApplyFilters(short[] buffer, int readSamples)
override int FillStreamBuffer(int samplePos, short[] buffer)
float??? CurrentAmplitude
override float GetAmplitudeAtPlaybackPos(int playbackPos)
void SetPosition(Vector3? pos)
VoipSound(Client targetClient, SoundManager owner, VoipQueue q)
override SoundChannel Play(float gain, float range, Vector2 position, bool muffle=false)
override SoundChannel Play(float gain)
override SoundChannel Play(Vector3? position, float gain, float freqMult=1.0f, bool muffle=false)
override SoundChannel Play()
override SoundManager.SourcePoolIndex SourcePoolIndex