From d446b20e33592a27060bf59af41f7d32bc795de2 Mon Sep 17 00:00:00 2001 From: xen-42 Date: Fri, 26 Jan 2024 19:54:15 -0500 Subject: [PATCH] Sync audio mix rate (#6) --- addons/GodotVoipNet/Scripts/VoiceInstance.cs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/addons/GodotVoipNet/Scripts/VoiceInstance.cs b/addons/GodotVoipNet/Scripts/VoiceInstance.cs index 73ca213..2713a79 100644 --- a/addons/GodotVoipNet/Scripts/VoiceInstance.cs +++ b/addons/GodotVoipNet/Scripts/VoiceInstance.cs @@ -40,13 +40,14 @@ private void CreateMic() _audioEffectCapture = (AudioEffectCapture)AudioServer.GetBusEffect(recordBusIdx, 0); } - private void CreateVoice() + private void CreateVoice(float mixRate) { _voice = new AudioStreamPlayer(); AddChild(_voice); var generator = new AudioStreamGenerator(); generator.BufferLength = 0.1f; + generator.MixRate = mixRate; _voice.Stream = generator; _voice.Play(); @@ -54,11 +55,11 @@ private void CreateVoice() } [Rpc(CallLocal = false, TransferMode = MultiplayerPeer.TransferModeEnum.Reliable)] - public void Speak(Array data, int id) + public void Speak(Array data, int id, float mixRate) { if (_playback is null) { - CreateVoice(); + CreateVoice(mixRate); } ReceivedVoiceData?.Invoke(this, new VoiceDataEventArgs(data, id)); @@ -110,9 +111,9 @@ private void ProcessMic() } if (ShouldListen) { - Speak(data, Multiplayer.GetUniqueId()); + Speak(data, Multiplayer.GetUniqueId(), AudioServer.GetMixRate()); } - Rpc(nameof(Speak), new Variant[] { data, Multiplayer.GetUniqueId() }); + Rpc(nameof(Speak), new Variant[] { data, Multiplayer.GetUniqueId(), AudioServer.GetMixRate() }); SentVoiceData?.Invoke(this, new VoiceDataEventArgs(data, Multiplayer.GetUniqueId())); } }