FVoiceChatSystem
- Module
- VoiceChat
- Header
#include "VoiceChat/FVoiceChatSystem.h"- Namespace
Mowo
Type aliases
| Alias | Description |
|---|---|
using FPacketSink = std::function<void(uint32_t peerId, const uint8_t* data, size_t len, NetworkChannel channel)> | |
using FPositionProvider = std::function<bool(uint32_t peerId, Vec3& outPosition)> | |
using FOcclusionProvider = std::function<FSoundOcclusionResult(const Vec3& from, const Vec3& to)> | |
using FSpeakingChangedHandler = std::function<void(const FVoiceSpeakerInfo& info)> | |
using FRadioCarrierProvider = std::function<void(std::vector<FVoiceRadioCarrier>& outCarriers)> | |
using FRadioNoiseHandler = std::function<void(const Vec3& position, float loudness)> | |
using FGrainProvider = std::function<float(uint32_t peerId, const Vec3& speaker, const Vec3& listener)> | Extra grain for a voice travelling from speaker to listener, 0..1 — the game's own reason a voice breaks up (darkness, interference) on top of distance. The larger of this and the distance grain applies. |
using FPlaybackTap = std::function<void(uint32_t peerId, const int16_t* samples, uint32_t sampleCount, bool realFrame)> | Every frame handed to a speaker's playback stream, after decode and loss recovery. Tools and tests listen here; it runs whether or not an audio device exists. |
Properties
| Type | Name | Description |
|---|---|---|
static constexpr uint32_t | kSampleRate | The ADPCM format, and the format the system runs at before a codec is chosen. GetSampleRate()/GetFrameSamples() report what is ACTUALLY running; anything sizing a buffer must ask those. Default 16000. |
static constexpr uint32_t | kFrameSamples | Default 320. |
static constexpr float | kFrameSeconds | Default static_cast<float>(kFrameSamples) / static_cast<float>(kSampleRate). |
static constexpr size_t | kPacketHeaderBytes | Default 14. |
static constexpr uint8_t | kPacketMagic0 | Default 'M'. |
static constexpr uint8_t | kPacketMagic1 | Default 'V'. |
static constexpr uint8_t | kPacketVersion | Default 1. |
static constexpr uint32_t | kInvalidPeerId | Default 0xFFFFFFFFu. |
static constexpr uint32_t | kMaxRadioEmitters | A listener hears a transmission from its own radio plus at most this many of the nearest others. Default 4. |
static constexpr uint8_t | kFlagMimicryConsent | Header byte 5. The talker's own client sets it on every frame, so a change of mind takes effect on the next 20 ms, and the relay copies it through untouched. Default 0x01. |
Constructors
| Signature | Name | Description |
|---|---|---|
FVoiceChatSystem() | FVoiceChatSystem | Both defined out of line: the capture device, the capture ring and the per-speaker playback source are all incomplete here. |
~FVoiceChatSystem() override | ~FVoiceChatSystem | |
FVoiceChatSystem(const FVoiceChatSystem&) = delete | FVoiceChatSystem |
Public functions
| Returns | Name | Description |
|---|---|---|
FVoiceChatSystem& | operator= | |
void | Initialize | |
void | Update | |
void | Shutdown | |
uint32_t | GetSampleRate | The active codec's format. |
uint32_t | GetFrameSamples | |
float | GetFrameSeconds | |
std::vector<FVoiceDeviceInfo> | EnumerateInputDevices | Capture devices |
bool | SetInputDevice | |
const std::string& | GetInputDevice | |
bool | StartCapture | |
void | StopCapture | |
bool | IsCapturing | |
void | PushCapturedSamples | Feeds captured PCM into the lock-free ring. |
void | SetMode | Transmission |
EVoiceMode | GetMode | |
void | SetPushToTalkHeld | |
bool | IsPushToTalkHeld | |
void | SetRadioKeyHeld | |
bool | IsRadioKeyHeld | |
EVoiceTransmitChannel | GetActiveTransmitChannel | |
void | SetEnergyGate | Open-mic energy gate. |
float | GetGateOpenRms | |
float | GetGateCloseRms | |
bool | IsGateOpen | |
float | GetLastCaptureRms | |
void | SetInputGain | Linear gain applied to captured samples before the gate reads their energy, so raising it opens the gate on a quiet microphone instead of only making an already-transmitting voice louder. |
float | GetInputGain | |
void | SetProcessorSettings | Echo cancellation, noise suppression and automatic gain, run on every captured frame before the gate reads it and before it is encoded — the gate then opens on speech rather than on a fan, and nobody hears themselves come back out of someone's speakers. |
const FVoiceProcessorSettings& | GetProcessorSettings | |
const FVoiceProcessor& | GetProcessor | |
void | SetSelfMuted | |
bool | IsSelfMuted | |
bool | IsPlatformMuted | Mute and deafen mirrored from the player's platform voice client (Discord) while voice.FollowPlatformMute is on. |
bool | IsPlatformDeafened | |
void | ApplyPlatformVoiceState | |
void | SetPeerMuted | Playback. |
bool | IsPeerMuted | |
void | SetPeerVolume | |
float | GetPeerVolume | |
void | SetMasterVoiceVolume | |
float | GetMasterVoiceVolume | |
void | SetHearingRange | Proximity |
float | GetHearingMinDistance | |
float | GetHearingMaxDistance | |
void | SetRolloff | |
float | GetRolloff | |
void | SetProximityHysteresis | Fraction of MaxDistance added to the LEAVE threshold. |
float | GetProximityHysteresis | |
float | EvaluateAttenuation | Gain a listener at distance hears a proximity speaker at, 0..1. |
bool | IsAudibleTo | True when listenerPeerId is inside the speaker's hearing range, hysteresis included. |
void | SetDistanceLowPass | Three layers, each a different cue, so a listener can tell a far voice from a walled one: distance takes level and top end (the low-pass slides from nearHz at MinDistance to farHz at MaxDistance, interpolated in log frequency), occlusion takes level and top end by the wall's material, and grain takes fidelity — past startFraction of the hearing range the voice breaks up, reaching maxAmount at its edge. |
float | GetDistanceLowPassNear | |
float | GetDistanceLowPassFar | |
float | EvaluateDistanceCutoff | |
void | SetGrainRange | |
float | GetGrainStart | |
float | GetGrainMax | |
float | EvaluateDistanceGrain | |
void | SetGrainProvider | |
void | SetOcclusionEnabled | Occlusion |
bool | IsOcclusionEnabled | |
void | SetRadioCarrierProvider | Radio speakers. |
void | SetRadioNoiseHandler | |
void | SetRadioSpeakerRange | |
float | GetRadioSpeakerRange | |
void | SetRadioVolume | |
float | GetRadioVolume | |
void | SetRadioBandPassEnabled | |
bool | IsRadioBandPassEnabled | |
std::vector<FVoiceRadioEmitterInfo> | GetRadioEmitters | |
float | EvaluateRadioAttenuation | Gain a listener at distance hears another carrier's radio at: full out to a metre, the inverse law to the speaker range, silence past it. |
void | SetOcclusionSmoothing | How fast a voice glides onto a new occlusion target, per second. |
float | GetOcclusionSmoothing | |
void | SetBytesPerSecondBudget | Bandwidth. |
uint32_t | GetBytesPerSecondBudget | |
float | GetByteTokens | |
void | SetLocalPeerId | Networking |
uint32_t | GetLocalPeerId | |
void | SetIsServer | |
bool | IsServer | |
void | RegisterPeer | |
void | UnregisterPeer | |
std::vector<uint32_t> | GetPeerIds | |
void | SetPacketSink | |
void | ClearPacketSink | |
void | SetPlaybackTap | |
void | SetPlaybackTap | Keyed taps for features that live with the scene (auto-subtitles): one per owner, re-registering replaces, null removes. |
void | SetMimicryConsent | Mimicry. |
bool | GetMimicryConsent | |
void | SetFragmentCaptureEnabled | |
bool | IsFragmentCaptureEnabled | |
bool | HasPeerMimicryConsent | |
FVoiceFragmentBuffer& | GetFragmentBuffer | |
const FVoiceFragmentBuffer& | GetFragmentBuffer | |
void | SetPositionProvider | |
void | SetOcclusionProvider | |
uint32_t | OcclusionLayerMask | The layers a voice occlusion ray may stop on — FSoundOcclusion's, so a voice and a world sound stop on the same bodies. |
void | SetListenerPosition | |
bool | HandleIncomingPacket | Decodes one voice packet. |
bool | OnIncomingPacket | The NetworkManager data-observer entry point — true means consumed. |
bool | IsSpeaking | Speaking state |
bool | IsLocalSpeaking | |
bool | IsAnyoneSpeakingNearby | |
bool | TryGetSpeakerInfo | |
std::vector<FVoiceSpeakerInfo> | GetSpeakers | |
int32_t | AddSpeakingChangedHandler | |
void | RemoveSpeakingChangedHandler | |
void | ClearSpeakingChangedHandlers | |
void | SetSpeakingChangedHandler | Keyed registration for scene-lifetime handlers: re-registering the same owner REPLACES its handler instead of appending, so idempotent attach passes (Scene wiring, plugin hooks) never accumulate duplicates and never need a Clear whose ordering could drop another owner's hook — the bug shape that forced WireVoiceChat to run before the modular attach pass. |
IVoiceCodec* | GetCodec | Codec |
void | SetCodec | |
bool | SelectCodec | Installs the codec the preference names. |
EVoiceCodecPreference | GetCodecPreference | |
EVoiceCodecPreference | ParseCodecPreference | "auto" / "opus" / "adpcm" — the spelling the voice.Codec cvar and the settings screen both use. |
const char* | CodecPreferenceName | |
const FVoiceStats& | GetStats | |
void | ResetStats | |
const FVoiceJitterBuffer* | FindJitterBuffer | |
uint32_t | GetQueuedCaptureSamples | |
void | SetJitterDepth | Jitter tuning — target lead in frames and the hard queue ceiling. |
FVoiceChatSystem* | GetActive | |
void | WritePacketHeader | Header writer/reader, exposed so a test can build a malformed packet without duplicating the layout. |
Function details
FVoiceChatSystem
FVoiceChatSystem()Both defined out of line: the capture device, the capture ring and the per-speaker playback source are all incomplete here.
~FVoiceChatSystem
~FVoiceChatSystem() overrideFVoiceChatSystem
FVoiceChatSystem(const FVoiceChatSystem&) = deleteoperator=
FVoiceChatSystem& operator=(const FVoiceChatSystem&) = deleteInitialize
void Initialize(World* world) overrideUpdate
void Update(float deltaTime) overrideShutdown
void Shutdown() overrideGetSampleRate
uint32_t GetSampleRate() constThe active codec's format. Every frame the system captures, encodes, buffers and plays is this many samples at this rate.
GetFrameSamples
uint32_t GetFrameSamples() constGetFrameSeconds
float GetFrameSeconds() constEnumerateInputDevices
static std::vector<FVoiceDeviceInfo> EnumerateInputDevices()Capture devices
SetInputDevice
bool SetInputDevice(const std::string& deviceId)GetInputDevice
const std::string& GetInputDevice() constStartCapture
bool StartCapture()StopCapture
void StopCapture()IsCapturing
bool IsCapturing() constPushCapturedSamples
void PushCapturedSamples(const int16_t* samples, uint32_t count)Feeds captured PCM into the lock-free ring. Called from the miniaudio capture callback, which is why it neither allocates nor locks; also the injection point for headless drivers and tests.
SetMode
void SetMode(EVoiceMode mode)Transmission
GetMode
EVoiceMode GetMode() constSetPushToTalkHeld
void SetPushToTalkHeld(bool held)IsPushToTalkHeld
bool IsPushToTalkHeld() constSetRadioKeyHeld
void SetRadioKeyHeld(bool held)IsRadioKeyHeld
bool IsRadioKeyHeld() constGetActiveTransmitChannel
EVoiceTransmitChannel GetActiveTransmitChannel() constSetEnergyGate
void SetEnergyGate(float openRms, float closeRms, float holdSeconds)Open-mic energy gate. Opens at openRms, closes only below closeRms (hysteresis against a voice sitting on the threshold) and holds open for holdSeconds after the last loud frame so word gaps do not chop.
GetGateOpenRms
float GetGateOpenRms() constGetGateCloseRms
float GetGateCloseRms() constIsGateOpen
bool IsGateOpen() constGetLastCaptureRms
float GetLastCaptureRms() constSetInputGain
void SetInputGain(float gain)Linear gain applied to captured samples before the gate reads their energy, so raising it opens the gate on a quiet microphone instead of only making an already-transmitting voice louder.
GetInputGain
float GetInputGain() constSetProcessorSettings
void SetProcessorSettings(const FVoiceProcessorSettings& settings)Echo cancellation, noise suppression and automatic gain, run on every captured frame before the gate reads it and before it is encoded — the gate then opens on speech rather than on a fan, and nobody hears themselves come back out of someone's speakers.
GetProcessorSettings
const FVoiceProcessorSettings& GetProcessorSettings() constGetProcessor
const FVoiceProcessor& GetProcessor() constSetSelfMuted
void SetSelfMuted(bool muted)IsSelfMuted
bool IsSelfMuted() constIsPlatformMuted
bool IsPlatformMuted() constMute and deafen mirrored from the player's platform voice client (Discord) while voice.FollowPlatformMute is on. Kept apart from the in-game mute so unmuting in Discord never unmutes a player who muted here as well.
IsPlatformDeafened
bool IsPlatformDeafened() constApplyPlatformVoiceState
void ApplyPlatformVoiceState(bool muted, bool deafened)SetPeerMuted
void SetPeerMuted(uint32_t peerId, bool muted)Playback. Muting takes effect on what is already in flight too: the speaker's queued packets and the samples waiting in its playback stream are dropped, its radios close, and anything kept of its voice for mimicry is forgotten.
IsPeerMuted
bool IsPeerMuted(uint32_t peerId) constSetPeerVolume
void SetPeerVolume(uint32_t peerId, float volume)GetPeerVolume
float GetPeerVolume(uint32_t peerId) constSetMasterVoiceVolume
void SetMasterVoiceVolume(float volume)GetMasterVoiceVolume
float GetMasterVoiceVolume() constSetHearingRange
void SetHearingRange(float minDistance, float maxDistance)Proximity
GetHearingMinDistance
float GetHearingMinDistance() constGetHearingMaxDistance
float GetHearingMaxDistance() constSetRolloff
void SetRolloff(float rolloff)GetRolloff
float GetRolloff() constSetProximityHysteresis
void SetProximityHysteresis(float fraction)Fraction of MaxDistance added to the LEAVE threshold. 0.15 means a peer enters the relay set at MaxDistance and only leaves past 1.15x it.
GetProximityHysteresis
float GetProximityHysteresis() constEvaluateAttenuation
float EvaluateAttenuation(float distance) constGain a listener at distance hears a proximity speaker at, 0..1. The same inverse-with-rolloff curve miniaudio's default attenuation applies, evaluated on the CPU so the relay decision and the test can agree with what the mixer does.
IsAudibleTo
bool IsAudibleTo(uint32_t speakerPeerId, uint32_t listenerPeerId, EVoiceTransmitChannel channel)True when listenerPeerId is inside the speaker's hearing range, hysteresis included. Radio always returns true. Unresolvable positions fail OPEN — a missing pawn must not silence a player.
SetDistanceLowPass
void SetDistanceLowPass(float nearHz, float farHz)Three layers, each a different cue, so a listener can tell a far voice from a walled one: distance takes level and top end (the low-pass slides from nearHz at MinDistance to farHz at MaxDistance, interpolated in log frequency), occlusion takes level and top end by the wall's material, and grain takes fidelity — past startFraction of the hearing range the voice breaks up, reaching maxAmount at its edge. A nearHz at or above 19999 Hz with an equal farHz switches the distance low-pass off; a maxAmount of 0 switches grain off.
GetDistanceLowPassNear
float GetDistanceLowPassNear() constGetDistanceLowPassFar
float GetDistanceLowPassFar() constEvaluateDistanceCutoff
float EvaluateDistanceCutoff(float distance) constSetGrainRange
void SetGrainRange(float startFraction, float maxAmount)GetGrainStart
float GetGrainStart() constGetGrainMax
float GetGrainMax() constEvaluateDistanceGrain
float EvaluateDistanceGrain(float distance) constSetGrainProvider
void SetGrainProvider(FGrainProvider provider)SetOcclusionEnabled
void SetOcclusionEnabled(bool enabled)Occlusion
IsOcclusionEnabled
bool IsOcclusionEnabled() constSetRadioCarrierProvider
void SetRadioCarrierProvider(FRadioCarrierProvider provider)Radio speakers. The provider lists every carrier and where their radio hangs; without one the only radio is the listener's own, at the listener. Another carrier's radio is audible out to the speaker range.
SetRadioNoiseHandler
void SetRadioNoiseHandler(FRadioNoiseHandler handler)SetRadioSpeakerRange
void SetRadioSpeakerRange(float meters)GetRadioSpeakerRange
float GetRadioSpeakerRange() constSetRadioVolume
void SetRadioVolume(float volume)GetRadioVolume
float GetRadioVolume() constSetRadioBandPassEnabled
void SetRadioBandPassEnabled(bool enabled)IsRadioBandPassEnabled
bool IsRadioBandPassEnabled() constGetRadioEmitters
std::vector<FVoiceRadioEmitterInfo> GetRadioEmitters(uint32_t speakerPeerId) constEvaluateRadioAttenuation
float EvaluateRadioAttenuation(float distance) constGain a listener at distance hears another carrier's radio at: full out to a metre, the inverse law to the speaker range, silence past it.
SetOcclusionSmoothing
void SetOcclusionSmoothing(float ratePerSecond)How fast a voice glides onto a new occlusion target, per second. Zero or less means the shared rate from the occlusion table.
GetOcclusionSmoothing
float GetOcclusionSmoothing() constSetBytesPerSecondBudget
void SetBytesPerSecondBudget(uint32_t bytesPerSecond)Bandwidth. A hard per-client cap in bytes/second over the outgoing voice stream; frames over budget are DROPPED, never queued — a queued voice frame is a stale voice frame.
GetBytesPerSecondBudget
uint32_t GetBytesPerSecondBudget() constGetByteTokens
float GetByteTokens() constSetLocalPeerId
void SetLocalPeerId(uint32_t peerId)Networking
GetLocalPeerId
uint32_t GetLocalPeerId() constSetIsServer
void SetIsServer(bool isServer)IsServer
bool IsServer() constRegisterPeer
void RegisterPeer(uint32_t peerId)UnregisterPeer
void UnregisterPeer(uint32_t peerId)GetPeerIds
std::vector<uint32_t> GetPeerIds() constSetPacketSink
void SetPacketSink(FPacketSink sink)ClearPacketSink
void ClearPacketSink()SetPlaybackTap
void SetPlaybackTap(FPlaybackTap tap)SetPlaybackTap
void SetPlaybackTap(const char* owner, FPlaybackTap tap)Keyed taps for features that live with the scene (auto-subtitles): one per owner, re-registering replaces, null removes. They hear what the player hears — a muted or deafened speaker is silence here too.
SetMimicryConsent
void SetMimicryConsent(bool consent)Mimicry. The local player's consent to have their voice kept as short fragments by whoever hosts the creature (voice.MimicryConsent, on by default — the opt-out lives on the player's settings screen), stamped on every frame this client sends. Capture is the receiving side's choice (voice.MimicryCapture, off by default): only a host that runs a mimic turns it on, and it keeps only consenting, unmuted talkers.
GetMimicryConsent
bool GetMimicryConsent() constSetFragmentCaptureEnabled
void SetFragmentCaptureEnabled(bool enabled)IsFragmentCaptureEnabled
bool IsFragmentCaptureEnabled() constHasPeerMimicryConsent
bool HasPeerMimicryConsent(uint32_t peerId) constGetFragmentBuffer
FVoiceFragmentBuffer& GetFragmentBuffer()GetFragmentBuffer
const FVoiceFragmentBuffer& GetFragmentBuffer() constSetPositionProvider
void SetPositionProvider(FPositionProvider provider)SetOcclusionProvider
void SetOcclusionProvider(FOcclusionProvider provider)OcclusionLayerMask
static uint32_t OcclusionLayerMask()The layers a voice occlusion ray may stop on — FSoundOcclusion's, so a voice and a world sound stop on the same bodies.
SetListenerPosition
void SetListenerPosition(const Vec3& position)HandleIncomingPacket
bool HandleIncomingPacket(uint32_t senderPeerId, const uint8_t* data, size_t len)Decodes one voice packet. On a server it also relays the frame to the peers that can hear it. Returns false when the packet was refused.
OnIncomingPacket
bool OnIncomingPacket(const NetworkEvent& evt)The NetworkManager data-observer entry point — true means consumed.
IsSpeaking
bool IsSpeaking(uint32_t peerId) constSpeaking state
IsLocalSpeaking
bool IsLocalSpeaking() constIsAnyoneSpeakingNearby
bool IsAnyoneSpeakingNearby() constTryGetSpeakerInfo
bool TryGetSpeakerInfo(uint32_t peerId, FVoiceSpeakerInfo& out) constGetSpeakers
std::vector<FVoiceSpeakerInfo> GetSpeakers() constAddSpeakingChangedHandler
int32_t AddSpeakingChangedHandler(FSpeakingChangedHandler handler)RemoveSpeakingChangedHandler
void RemoveSpeakingChangedHandler(int32_t handle)ClearSpeakingChangedHandlers
void ClearSpeakingChangedHandlers()SetSpeakingChangedHandler
void SetSpeakingChangedHandler(const char* owner, FSpeakingChangedHandler handler)Keyed registration for scene-lifetime handlers: re-registering the same owner REPLACES its handler instead of appending, so idempotent attach passes (Scene wiring, plugin hooks) never accumulate duplicates and never need a Clear whose ordering could drop another owner's hook — the bug shape that forced WireVoiceChat to run before the modular attach pass.
GetCodec
IVoiceCodec* GetCodec() constCodec
SetCodec
void SetCodec(std::unique_ptr<IVoiceCodec> codec)SelectCodec
bool SelectCodec(EVoiceCodecPreference preference)Installs the codec the preference names. False when the preference named Opus and this build has no Opus — the caller learns the request was refused instead of finding out from the pitch of the session.
GetCodecPreference
EVoiceCodecPreference GetCodecPreference() constParseCodecPreference
static EVoiceCodecPreference ParseCodecPreference(const std::string& name)"auto" / "opus" / "adpcm" — the spelling the voice.Codec cvar and the settings screen both use. Anything else reads as Auto.
CodecPreferenceName
static const char* CodecPreferenceName(EVoiceCodecPreference preference)GetStats
const FVoiceStats& GetStats() constResetStats
void ResetStats()FindJitterBuffer
const FVoiceJitterBuffer* FindJitterBuffer(uint32_t peerId) constGetQueuedCaptureSamples
uint32_t GetQueuedCaptureSamples() constSetJitterDepth
void SetJitterDepth(uint32_t targetFrames, uint32_t maxFrames)Jitter tuning — target lead in frames and the hard queue ceiling.
GetActive
static FVoiceChatSystem* GetActive()WritePacketHeader
static void WritePacketHeader(uint8_t* out, EVoiceCodecId codec, EVoiceTransmitChannel channel, uint32_t speakerPeerId, uint16_t sequence, uint16_t payloadLen, uint8_t flags = 0)Header writer/reader, exposed so a test can build a malformed packet without duplicating the layout.