Class AudioServer
Server interface for low-level audio access.
- Inheritance
-
AudioServer
Remarks
AudioServer is a low-level server interface for audio access. It is in charge of creating sample data (playable audio) as well as its playback via a voice interface.
See Also
Properties
bus_count
Number of available audio buses.
var bus_count : int = 1
Property Value
Remarks
input_device
Name of the current device for audio input (see get_input_device_list). 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: 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.
var input_device : String = "Default"
Property Value
Remarks
output_device
Name of the current device for audio output (see get_output_device_list). 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"
.
var output_device : String = "Default"
Property Value
Remarks
playback_speed_scale
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 time_scale to affect the general simulation speed, which is independent from playback_speed_scale.
var playback_speed_scale : float = 1.0
Property Value
Remarks
Methods
add_bus(int)
Adds a bus at at_position
.
void add_bus(int at_position)
Parameters
at_position
int
add_bus_effect(int, AudioEffect, int)
Adds an AudioEffect effect to the bus bus_idx
at at_position
.
void add_bus_effect(int bus_idx, AudioEffect effect, int at_position)
Parameters
bus_idx
inteffect
AudioEffectat_position
int
generate_bus_layout
Qualifiers: const
Generates an AudioBusLayout using the available buses and effects.
AudioBusLayout generate_bus_layout
get_bus_channels(int)
Qualifiers: const
Returns the number of channels of the bus at index bus_idx
.
int get_bus_channels(int bus_idx)
Parameters
bus_idx
int
get_bus_effect(int, int)
Returns the AudioEffect at position effect_idx
in bus bus_idx
.
AudioEffect get_bus_effect(int bus_idx, int effect_idx)
Parameters
get_bus_effect_count(int)
Returns the number of effects on the bus at bus_idx
.
int get_bus_effect_count(int bus_idx)
Parameters
bus_idx
int
get_bus_effect_instance(int, int, int)
Returns the AudioEffectInstance assigned to the given bus and effect indices (and optionally channel).
AudioEffectInstance get_bus_effect_instance(int bus_idx, int effect_idx, int channel)
Parameters
get_bus_index(StringName)
Qualifiers: const
Returns the index of the bus with the name bus_name
. Returns -1
if no bus with the specified name exist.
int get_bus_index(StringName bus_name)
Parameters
bus_name
StringName
get_bus_name(int)
Qualifiers: const
Returns the name of the bus with the index bus_idx
.
String get_bus_name(int bus_idx)
Parameters
bus_idx
int
get_bus_peak_volume_left_db(int, int)
Qualifiers: const
Returns the peak volume of the left speaker at bus index bus_idx
and channel index channel
.
float get_bus_peak_volume_left_db(int bus_idx, int channel)
Parameters
get_bus_peak_volume_right_db(int, int)
Qualifiers: const
Returns the peak volume of the right speaker at bus index bus_idx
and channel index channel
.
float get_bus_peak_volume_right_db(int bus_idx, int channel)
Parameters
get_bus_send(int)
Qualifiers: const
Returns the name of the bus that the bus at index bus_idx
sends to.
StringName get_bus_send(int bus_idx)
Parameters
bus_idx
int
get_bus_volume_db(int)
Qualifiers: const
Returns the volume of the bus at index bus_idx
in dB.
float get_bus_volume_db(int bus_idx)
Parameters
bus_idx
int
get_bus_volume_linear(int)
Qualifiers: const
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.get_bus_volume_db.
float get_bus_volume_linear(int bus_idx)
Parameters
bus_idx
int
get_driver_name
Qualifiers: const
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 audio/driver/driver.
String get_driver_name
get_input_device_list
Returns the names of all audio input devices detected on the system.
Note: 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.
PackedStringArray get_input_device_list
get_input_mix_rate
Qualifiers: const
Returns the sample rate at the input of the AudioServer.
float get_input_mix_rate
get_mix_rate
Qualifiers: const
Returns the sample rate at the output of the AudioServer.
float get_mix_rate
get_output_device_list
Returns the names of all audio output devices detected on the system.
PackedStringArray get_output_device_list
get_output_latency
Qualifiers: const
Returns the audio driver's effective output latency. This is based on 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 get_output_latency every frame.
float get_output_latency
get_speaker_mode
Qualifiers: const
Returns the speaker configuration.
int get_speaker_mode
get_time_since_last_mix
Qualifiers: const
Returns the relative time since the last mix occurred.
float get_time_since_last_mix
get_time_to_next_mix
Qualifiers: const
Returns the relative time until the next mix occurs.
float get_time_to_next_mix
is_bus_bypassing_effects(int)
Qualifiers: const
If true
, the bus at index bus_idx
is bypassing effects.
bool is_bus_bypassing_effects(int bus_idx)
Parameters
bus_idx
int
is_bus_effect_enabled(int, int)
Qualifiers: const
If true
, the effect at index effect_idx
on the bus at index bus_idx
is enabled.
bool is_bus_effect_enabled(int bus_idx, int effect_idx)
Parameters
is_bus_mute(int)
Qualifiers: const
If true
, the bus at index bus_idx
is muted.
bool is_bus_mute(int bus_idx)
Parameters
bus_idx
int
is_bus_solo(int)
Qualifiers: const
If true
, the bus at index bus_idx
is in solo mode.
bool is_bus_solo(int bus_idx)
Parameters
bus_idx
int
is_stream_registered_as_sample(AudioStream)
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.register_stream_as_sample.
bool is_stream_registered_as_sample(AudioStream stream)
Parameters
stream
AudioStream
lock
Locks the audio driver's main loop.
Note: Remember to unlock it afterwards.
void lock
move_bus(int, int)
Moves the bus from index index
to index to_index
.
void move_bus(int index, int to_index)
Parameters
register_stream_as_sample(AudioStream)
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.
void register_stream_as_sample(AudioStream stream)
Parameters
stream
AudioStream
remove_bus(int)
Removes the bus at index index
.
void remove_bus(int index)
Parameters
index
int
remove_bus_effect(int, int)
Removes the effect at index effect_idx
from the bus at index bus_idx
.
void remove_bus_effect(int bus_idx, int effect_idx)
Parameters
set_bus_bypass_effects(int, bool)
If true
, the bus at index bus_idx
is bypassing effects.
void set_bus_bypass_effects(int bus_idx, bool enable)
Parameters
set_bus_effect_enabled(int, int, bool)
If true
, the effect at index effect_idx
on the bus at index bus_idx
is enabled.
void set_bus_effect_enabled(int bus_idx, int effect_idx, bool enabled)
Parameters
set_bus_layout(AudioBusLayout)
Overwrites the currently used AudioBusLayout.
void set_bus_layout(AudioBusLayout bus_layout)
Parameters
bus_layout
AudioBusLayout
set_bus_mute(int, bool)
If true
, the bus at index bus_idx
is muted.
void set_bus_mute(int bus_idx, bool enable)
Parameters
set_bus_name(int, String)
Sets the name of the bus at index bus_idx
to name
.
void set_bus_name(int bus_idx, String name)
Parameters
set_bus_send(int, StringName)
Connects the output of the bus at bus_idx
to the bus named send
.
void set_bus_send(int bus_idx, StringName send)
Parameters
bus_idx
intsend
StringName
set_bus_solo(int, bool)
If true
, the bus at index bus_idx
is in solo mode.
void set_bus_solo(int bus_idx, bool enable)
Parameters
set_bus_volume_db(int, float)
Sets the volume in decibels of the bus at index bus_idx
to volume_db
.
void set_bus_volume_db(int bus_idx, float volume_db)
Parameters
set_bus_volume_linear(int, float)
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.set_bus_volume_db with the result of @GlobalScope.linear_to_db on a value.
void set_bus_volume_linear(int bus_idx, float volume_linear)
Parameters
set_enable_tagging_used_audio_streams(bool)
If set to true
, all instances of AudioStreamPlayback will call _tag_used_streams every mix step.
Note: This is enabled by default in the editor, as it is used by editor plugins for the audio stream previews.
void set_enable_tagging_used_audio_streams(bool enable)
Parameters
enable
bool
swap_bus_effects(int, int, int)
Swaps the position of two effects in bus bus_idx
.
void swap_bus_effects(int bus_idx, int effect_idx, int by_effect_idx)
Parameters
unlock
Unlocks the audio driver's main loop. (After locking it, you should always unlock it.)
void unlock
Events
bus_layout_changed
Emitted when an audio bus is added, deleted, or moved.
signal bus_layout_changed
bus_renamed(int, StringName, StringName)
Emitted when the audio bus at bus_index
is renamed from old_name
to new_name
.
signal bus_renamed(int bus_index, StringName old_name, StringName new_name)
Parameters
bus_index
intold_name
StringNamenew_name
StringName