voice.NumChannels

voice.NumChannels

#Overview

name: voice.NumChannels

This variable is created as a Console Variable (cvar).

It is referenced in 3 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of voice.NumChannels is to set the default number of audio channels for voice input and output in Unreal Engine’s Voice Over IP (VOIP) system. It determines how many channels are used to capture microphone input, encode it to Opus format, and output the audio.

This setting variable is primarily used by the Engine’s VOIP subsystem, which is part of the core Engine module. It’s specifically utilized in the voice configuration and processing components.

The value of this variable is set through a console variable (CVar) system. It’s initialized with a default value of 1 and can be modified at runtime or through configuration files.

The associated variable NumVoiceChannelsCvar directly interacts with voice.NumChannels. They share the same value, with NumVoiceChannelsCvar serving as the actual storage for the setting.

Developers must be aware that this variable only accepts values of either 1 or 2, representing mono or stereo audio respectively. Any other values will be clamped to this range.

Best practices when using this variable include:

  1. Consider the performance implications of using stereo (2 channels) over mono (1 channel), especially in multiplayer scenarios with many concurrent voice streams.
  2. Ensure that the rest of the audio pipeline can handle the chosen number of channels.
  3. Test thoroughly with both mono and stereo settings to ensure compatibility with various audio hardware and network conditions.

Regarding the associated variable NumVoiceChannelsCvar:

The purpose of NumVoiceChannelsCvar is to store the actual value of the voice.NumChannels setting within the engine’s code.

This variable is used internally by the Engine’s VOIP system, specifically in the VoiceConfig.cpp file.

The value of NumVoiceChannelsCvar is set through the FAutoConsoleVariableRef system, which binds it to the voice.NumChannels console variable.

It directly interacts with the voice.NumChannels CVar and is used in the GetVoiceNumChannels() function to return the current number of voice channels.

Developers should be aware that modifying NumVoiceChannelsCvar directly is not recommended. Instead, they should use the voice.NumChannels CVar to change the setting.

Best practices for NumVoiceChannelsCvar include:

  1. Treat it as a read-only variable in most scenarios.
  2. Use the UVOIPStatics::GetVoiceNumChannels() function to retrieve its value, which ensures the value is properly clamped between 1 and 2.
  3. Remember that changes to this variable will affect the entire VOIP system, so modifications should be made with caution and thorough testing.

#References in C++ code

#Callsites

This variable is referenced in the following C++ source code:

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/VoiceConfig.cpp:74

Scope: file

Source code excerpt:

static int32 NumVoiceChannelsCvar = 1;
FAutoConsoleVariableRef CVarNumVoiceChannels(
	TEXT("voice.NumChannels"),
	NumVoiceChannelsCvar,
	TEXT("Default number of channels to capture from mic input, encode to Opus, and output. Can be set to 1 or 2.\n")
	TEXT("Value: Number of channels to use for VOIP input and output."),
	ECVF_Default);

int32 UVOIPStatics::GetVoiceSampleRate()

#Associated Variable and Callsites

This variable is associated with another variable named NumVoiceChannelsCvar. They share the same value. See the following C++ source code.

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/VoiceConfig.cpp:72

Scope: file

Source code excerpt:

	ECVF_Default);

static int32 NumVoiceChannelsCvar = 1;
FAutoConsoleVariableRef CVarNumVoiceChannels(
	TEXT("voice.NumChannels"),
	NumVoiceChannelsCvar,
	TEXT("Default number of channels to capture from mic input, encode to Opus, and output. Can be set to 1 or 2.\n")
	TEXT("Value: Number of channels to use for VOIP input and output."),
	ECVF_Default);

int32 UVOIPStatics::GetVoiceSampleRate()
{

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/VoiceConfig.cpp:122

Scope (from outer to inner):

file
function     int32 UVOIPStatics::GetVoiceNumChannels

Source code excerpt:

int32 UVOIPStatics::GetVoiceNumChannels()
{
	return FMath::Clamp<int32>(NumVoiceChannelsCvar, 1, 2);
}

uint32 UVOIPStatics::GetMaxVoiceDataSize()
{
	int32 SampleRate = GetVoiceSampleRate();
	// This max voice data size is based on approximations of how large the