AudioServer
Manages the global mixer, buses and audio timing.
AudioServer configures buses across the running project. Sources send signals into buses; effects run in order, then bus gain applies and the result is sent to a receiving bus on the left. Master supplies the final mix.
Look up a bus by name with GetBusIndex() and check for -1. Indices change when the layout changes. Runtime adjustments do not automatically save the project resource. The mixer operates separately from game frames; its timing and latency estimates do not measure physical sound at the listener.
Declarations checked against C# SDK 1.0.0. Expand a name to see declarations and documentation.
Properties5
BusCountProperty
public static int BusCount { get; set; }Number of available audio buses.
InputDeviceProperty
public static string InputDevice { get; set; }Name of the current device for audio input (see AudioServer.GetInputDeviceList). On systems with multiple audio inputs (such as analog, USB and HDMI audio), this can be used to select the audio input device. The value "Default" will record audio on the system-wide default audio input. If an invalid device name is set, the value will be reverted back to "Default".
Note: ProjectSettings.audio/driver/enable_input must be true for audio input to work. See also that setting's description for caveats related to permissions and operating system privacy settings.
OutputDeviceProperty
public static string OutputDevice { get; set; }Name of the current device for audio output (see AudioServer.GetOutputDeviceList). On systems with multiple audio outputs (such as analog, USB and HDMI audio), this can be used to select the audio output device. The value "Default" will play audio on the system-wide default audio output. If an invalid device name is set, the value will be reverted back to "Default".
PlaybackSpeedScaleProperty
public static float PlaybackSpeedScale { get; set; }Scales the rate at which audio is played (i.e. setting it to 0.5 will make the audio be played at half its speed). See also Engine.TimeScale to affect the general simulation speed, which is independent from AudioServer.PlaybackSpeedScale.
SingletonProperty
public static AudioServerInstance Singleton { get; }Methods57
AddBusvoid
public static void AddBus(int atPosition = -1);Adds a bus at at_position.
| Name | Type | Default |
|---|---|---|
atPosition | int | -1 |
AddBusEffectvoid
public static void AddBusEffect(int busIdx, AudioEffect effect, int atPosition = -1);Adds an AudioEffect effect to the bus bus_idx at at_position.
| Name | Type | Default |
|---|---|---|
busIdx | int | — |
effect | AudioEffect | — |
atPosition | int | -1 |
GenerateBusLayoutAudioBusLayout
public static AudioBusLayout GenerateBusLayout();Generates an AudioBusLayout using the available buses and effects.
AudioBusLayoutGetBusChannelsint
public static int GetBusChannels(int busIdx);Returns the number of channels of the bus at index bus_idx.
| Name | Type | Default |
|---|---|---|
busIdx | int | — |
intGetBusCountint
public static int GetBusCount();intGetBusEffectAudioEffect
public static AudioEffect GetBusEffect(int busIdx, int effectIdx);Returns the AudioEffect at position effect_idx in bus bus_idx.
| Name | Type | Default |
|---|---|---|
busIdx | int | — |
effectIdx | int | — |
AudioEffectGetBusEffectCountint
public static int GetBusEffectCount(int busIdx);Returns the number of effects on the bus at bus_idx.
| Name | Type | Default |
|---|---|---|
busIdx | int | — |
intGetBusEffectInstanceAudioEffectInstance
public static AudioEffectInstance GetBusEffectInstance(int busIdx, int effectIdx, int channel = 0);Returns the AudioEffectInstance assigned to the given bus and effect indices (and optionally channel).
| Name | Type | Default |
|---|---|---|
busIdx | int | — |
effectIdx | int | — |
channel | int | 0 |
AudioEffectInstanceGetBusIndexint
public static int GetBusIndex(StringName busName);Returns the current bus index by name, or -1 when absent. Look it up again after layout changes; do not store it as a stable category identifier.
| Name | Type | Default |
|---|---|---|
busName | StringName | — |
intGetBusNamestring
public static string GetBusName(int busIdx);Returns the name of the bus with the index bus_idx.
| Name | Type | Default |
|---|---|---|
busIdx | int | — |
stringGetBusPeakVolumeLeftDbfloat
public static float GetBusPeakVolumeLeftDb(int busIdx, int channel);Returns the peak volume of the left speaker at bus index bus_idx and channel index channel.
| Name | Type | Default |
|---|---|---|
busIdx | int | — |
channel | int | — |
floatGetBusPeakVolumeRightDbfloat
public static float GetBusPeakVolumeRightDb(int busIdx, int channel);Returns the peak volume of the right speaker at bus index bus_idx and channel index channel.
| Name | Type | Default |
|---|---|---|
busIdx | int | — |
channel | int | — |
floatGetBusSendStringName
public static StringName GetBusSend(int busIdx);Returns the name of the bus that the bus at index bus_idx sends to.
| Name | Type | Default |
|---|---|---|
busIdx | int | — |
StringNameGetBusVolumeDbfloat
public static float GetBusVolumeDb(int busIdx);Returns the volume of the bus at index bus_idx in dB.
| Name | Type | Default |
|---|---|---|
busIdx | int | — |
floatGetBusVolumeLinearfloat
public static float GetBusVolumeLinear(int busIdx);Returns the volume of the bus at index bus_idx as a linear value.
Note: The returned value is equivalent to the result of @GlobalScope.db_to_linear on the result of AudioServer.GetBusVolumeDb.
| Name | Type | Default |
|---|---|---|
busIdx | int | — |
floatGetDriverNamestring
public static string GetDriverName();Returns the name of the current audio driver. The default usually depends on the operating system, but may be overridden via the --audio-driver command line argument. --headless also automatically sets the audio driver to Dummy. See also ProjectSettings.audio/driver/driver.
stringGetInputBufferLengthFramesint
public static int GetInputBufferLengthFrames();Returns the absolute size of the microphone input buffer. This is set to a multiple of the audio latency and can be used to estimate the minimum rate at which the frames need to be fetched.
intGetInputDevicestring
public static string GetInputDevice();stringGetInputDeviceListstring[]
public static string[] GetInputDeviceList();Returns the names of all audio input devices detected on the system.
Note: ProjectSettings.audio/driver/enable_input must be true for audio input to work. See also that setting's description for caveats related to permissions and operating system privacy settings.
string[]GetInputFramesVector2[]
public static Vector2[] GetInputFrames(int frames);Returns a Vector2[] containing exactly frames audio samples from the internal microphone buffer if available, otherwise returns an empty Vector2[].
The buffer is filled at the rate of AudioServer.GetInputMixRate frames per second when AudioServer.SetInputDeviceActive has successfully been set to true.
The samples are signed floating-point PCM values between -1 and 1.
| Name | Type | Default |
|---|---|---|
frames | int | — |
Vector2[]GetInputFramesAvailableint
public static int GetInputFramesAvailable();Returns the number of frames available to read using AudioServer.GetInputFrames.
intGetInputMixRatefloat
public static float GetInputMixRate();Returns the sample rate at the input of the AudioServer.
floatGetMixRatefloat
public static float GetMixRate();Returns the sample rate at the output of the AudioServer.
floatGetOutputDevicestring
public static string GetOutputDevice();stringGetOutputDeviceListstring[]
public static string[] GetOutputDeviceList();Returns the names of all audio output devices detected on the system.
string[]GetOutputLatencydouble
public static double GetOutputLatency();Returns the audio driver's effective output latency. This is based on ProjectSettings.audio/driver/output_latency, but the exact returned value will differ depending on the operating system and audio driver.
Note: This can be expensive; it is not recommended to call AudioServer.GetOutputLatency every frame.
doubleGetPlaybackSpeedScalefloat
public static float GetPlaybackSpeedScale();floatGetSpeakerModeAudioServer.SpeakerMode
public static AudioServer.SpeakerMode GetSpeakerMode();Returns the speaker configuration.
AudioServer.SpeakerModeGetTimeSinceLastMixdouble
public static double GetTimeSinceLastMix();Returns the relative time since the last mix occurred, in seconds.
doubleGetTimeToNextMixdouble
public static double GetTimeToNextMix();Returns the relative time until the next mix occurs, in seconds.
doubleIsBusBypassingEffectsbool
public static bool IsBusBypassingEffects(int busIdx);If true, the bus at index bus_idx is bypassing effects.
| Name | Type | Default |
|---|---|---|
busIdx | int | — |
boolIsBusEffectEnabledbool
public static bool IsBusEffectEnabled(int busIdx, int effectIdx);If true, the effect at index effect_idx on the bus at index bus_idx is enabled.
| Name | Type | Default |
|---|---|---|
busIdx | int | — |
effectIdx | int | — |
boolIsBusMutebool
public static bool IsBusMute(int busIdx);If true, the bus at index bus_idx is muted.
| Name | Type | Default |
|---|---|---|
busIdx | int | — |
boolIsBusSolobool
public static bool IsBusSolo(int busIdx);If true, the bus at index bus_idx is in solo mode.
| Name | Type | Default |
|---|---|---|
busIdx | int | — |
boolIsStreamRegisteredAsSamplebool
public static bool IsStreamRegisteredAsSample(AudioStream stream);If true, the stream is registered as a sample. The engine will not have to register it before playing the sample.
If false, the stream will have to be registered before playing it. To prevent lag spikes, register the stream as sample with AudioServer.RegisterStreamAsSample.
| Name | Type | Default |
|---|---|---|
stream | AudioStream | — |
boolLockvoid
public static void Lock();Locks the audio driver's main loop. Note: Remember to unlock it afterwards.
MoveBusvoid
public static void MoveBus(int index, int toIndex);Moves the bus from index index to index to_index.
| Name | Type | Default |
|---|---|---|
index | int | — |
toIndex | int | — |
RegisterStreamAsSamplevoid
public static void RegisterStreamAsSample(AudioStream stream);Forces the registration of a stream as a sample. Note: Lag spikes may occur when calling this method, especially on single-threaded builds. It is suggested to call this method while loading assets, where the lag spike could be masked, instead of registering the sample right before it needs to be played.
| Name | Type | Default |
|---|---|---|
stream | AudioStream | — |
RemoveBusvoid
public static void RemoveBus(int index);Removes the bus at index index.
| Name | Type | Default |
|---|---|---|
index | int | — |
RemoveBusEffectvoid
public static void RemoveBusEffect(int busIdx, int effectIdx);Removes the effect at index effect_idx from the bus at index bus_idx.
| Name | Type | Default |
|---|---|---|
busIdx | int | — |
effectIdx | int | — |
SetBusBypassEffectsvoid
public static void SetBusBypassEffects(int busIdx, bool enable);If true, the bus at index bus_idx is bypassing effects.
| Name | Type | Default |
|---|---|---|
busIdx | int | — |
enable | bool | — |
SetBusCountvoid
public static void SetBusCount(int amount);| Name | Type | Default |
|---|---|---|
amount | int | — |
SetBusEffectEnabledvoid
public static void SetBusEffectEnabled(int busIdx, int effectIdx, bool enabled);If true, the effect at index effect_idx on the bus at index bus_idx is enabled.
| Name | Type | Default |
|---|---|---|
busIdx | int | — |
effectIdx | int | — |
enabled | bool | — |
SetBusLayoutvoid
public static void SetBusLayout(AudioBusLayout busLayout);Overwrites the currently used AudioBusLayout.
| Name | Type | Default |
|---|---|---|
busLayout | AudioBusLayout | — |
SetBusMutevoid
public static void SetBusMute(int busIdx, bool enable);Mutes or restores a bus output without stopping or pausing its sources. That bus's effects are before mute, so Capture on it can still receive data.
| Name | Type | Default |
|---|---|---|
busIdx | int | — |
enable | bool | — |
SetBusNamevoid
public static void SetBusName(int busIdx, string name);Sets the name of the bus at index bus_idx to name.
| Name | Type | Default |
|---|---|---|
busIdx | int | — |
name | string | — |
SetBusSendvoid
public static void SetBusSend(int busIdx, StringName send);Sets the receiving bus by name. During processing it must be left of its sender; a missing name or a rightward/self route falls back to Master. Index 0 is Master and has no subsequent send.
| Name | Type | Default |
|---|---|---|
busIdx | int | — |
send | StringName | — |
SetBusSolovoid
public static void SetBusSolo(int busIdx, bool enable);If true, the bus at index bus_idx is in solo mode.
| Name | Type | Default |
|---|---|---|
busIdx | int | — |
enable | bool | — |
SetBusVolumeDbvoid
public static void SetBusVolumeDb(int busIdx, float volumeDb);Sets bus gain in dB: 0 is unity and about -6.02 halves amplitude. This is not a digital peak measurement in dBFS. Gain applies after bus effects and before sending onward. Mute is useful for a slider's zero position.
| Name | Type | Default |
|---|---|---|
busIdx | int | — |
volumeDb | float | — |
SetBusVolumeLinearvoid
public static void SetBusVolumeLinear(int busIdx, float volumeLinear);Sets the volume as a linear value of the bus at index bus_idx to volume_linear.
Note: Using this method is equivalent to calling AudioServer.SetBusVolumeDb with the result of @GlobalScope.linear_to_db on a value.
| Name | Type | Default |
|---|---|---|
busIdx | int | — |
volumeLinear | float | — |
SetEnableTaggingUsedAudioStreamsvoid
public static void SetEnableTaggingUsedAudioStreams(bool enable);If set to true, all instances of AudioStreamPlayback will call AudioStreamPlayback._TagUsedStreams every mix step.
Note: This is enabled by default in the editor, as it is used by editor plugins for the audio stream previews.
| Name | Type | Default |
|---|---|---|
enable | bool | — |
SetInputDevicevoid
public static void SetInputDevice(string name);| Name | Type | Default |
|---|---|---|
name | string | — |
SetInputDeviceActiveError
public static Error SetInputDeviceActive(bool active);If active is true, starts the microphone input stream specified by AudioServer.InputDevice or returns an error if it failed.
If active is false, stops the input stream if it is running.
| Name | Type | Default |
|---|---|---|
active | bool | — |
ErrorSetOutputDevicevoid
public static void SetOutputDevice(string name);| Name | Type | Default |
|---|---|---|
name | string | — |
SetPlaybackSpeedScalevoid
public static void SetPlaybackSpeedScale(float scale);| Name | Type | Default |
|---|---|---|
scale | float | — |
SwapBusEffectsvoid
public static void SwapBusEffects(int busIdx, int effectIdx, int byEffectIdx);Swaps the position of two effects in bus bus_idx.
| Name | Type | Default |
|---|---|---|
busIdx | int | — |
effectIdx | int | — |
byEffectIdx | int | — |
Unlockvoid
public static void Unlock();Unlocks the audio driver's main loop. (After locking it, you should always unlock it.)
Signals and events2
BusLayoutChangedEvent
public static event Action BusLayoutChanged;Emitted when an audio bus is added, deleted, or moved.
BusRenamedEvent
public static event AudioServer.BusRenamedEventHandler BusRenamed;Emitted when the audio bus at bus_index is renamed from old_name to new_name.
| Name | Type | Default |
|---|---|---|
busIndex | long | — |
oldName | StringName | — |
newName | StringName | — |
AudioServer.PlaybackType
| Value | Description |
|---|---|
Default = 0 | The playback will be considered of the type declared at |
Max = 3 | Represents the size of the |
Sample = 2 | Force the playback to be considered as a sample. This can provide lower latency and more stable playback (with less risk of audio crackling), at the cost of having less flexibility.
Note: Only currently supported on the web platform.
Note: |
Stream = 1 | Force the playback to be considered as a stream. |
AudioServer.SpeakerMode
| Value | Description |
|---|---|
ModeStereo = 0 | Two or fewer speakers were detected. |
Surround31 = 1 | A 3.1 channel surround setup was detected. |
Surround51 = 2 | A 5.1 channel surround setup was detected. |
Surround71 = 3 | A 7.1 channel surround setup was detected. |