Skip to content

Commit

Permalink
Sync audio mix rate (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
xen-42 authored Jan 27, 2024
1 parent 4a1c5c5 commit d446b20
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions addons/GodotVoipNet/Scripts/VoiceInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,25 +40,26 @@ 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();
_playback = _voice.GetStreamPlayback() as AudioStreamGeneratorPlayback;
}

[Rpc(CallLocal = false, TransferMode = MultiplayerPeer.TransferModeEnum.Reliable)]
public void Speak(Array<float> data, int id)
public void Speak(Array<float> data, int id, float mixRate)
{
if (_playback is null)
{
CreateVoice();
CreateVoice(mixRate);
}

ReceivedVoiceData?.Invoke(this, new VoiceDataEventArgs(data, id));
Expand Down Expand Up @@ -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()));
}
}
Expand Down

0 comments on commit d446b20

Please sign in to comment.