AudioServer

package
v0.0.0-...-20ed0ac Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 19, 2025 License: MIT Imports: 28 Imported by: 0

Documentation

Overview

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.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddBus

func AddBus()

Adds a bus at 'at_position'.

func AddBusEffect

func AddBusEffect(bus_idx Bus, effect AudioEffect.Instance)

Adds an AudioEffect effect to the bus 'bus_idx' at 'at_position'.

func AddBusEffectOptions

func AddBusEffectOptions(bus_idx Bus, effect AudioEffect.Instance, at_position int)

Adds an AudioEffect effect to the bus 'bus_idx' at 'at_position'.

func AddBusOptions

func AddBusOptions(at_position int)

Adds a bus at 'at_position'.

func Advanced

func Advanced() class

Advanced exposes a 1:1 low-level instance of the class, undocumented, for those who know what they are doing.

func BusCount

func BusCount() int

Number of available audio buses.

func GenerateBusLayout

func GenerateBusLayout() AudioBusLayout.Instance

Generates an AudioBusLayout using the available buses and effects.

func GetBusChannels

func GetBusChannels(bus_idx Bus) int

Returns the number of channels of the bus at index 'bus_idx'.

func GetBusEffect

func GetBusEffect(bus_idx Bus, effect_idx Effect) AudioEffect.Instance

Returns the AudioEffect at position 'effect_idx' in bus 'bus_idx'.

func GetBusEffectCount

func GetBusEffectCount(bus_idx Bus) int

Returns the number of effects on the bus at 'bus_idx'.

func GetBusEffectInstance

func GetBusEffectInstance(bus_idx Bus, effect_idx Effect, channel int) AudioEffectInstance.Instance

Returns the AudioEffectInstance assigned to the given bus and effect indices (and optionally channel).

func GetBusIndex

func GetBusIndex(bus_name string) int

Returns the index of the bus with the name 'bus_name'. Returns -1 if no bus with the specified name exist.

func GetBusName

func GetBusName(bus_idx Bus) string

Returns the name of the bus with the index 'bus_idx'.

func GetBusPeakVolumeLeftDb

func GetBusPeakVolumeLeftDb(bus_idx Bus, channel int) Float.X

Returns the peak volume of the left speaker at bus index 'bus_idx' and channel index 'channel'.

func GetBusPeakVolumeRightDb

func GetBusPeakVolumeRightDb(bus_idx Bus, channel int) Float.X

Returns the peak volume of the right speaker at bus index 'bus_idx' and channel index 'channel'.

func GetBusSend

func GetBusSend(bus_idx Bus) string

Returns the name of the bus that the bus at index 'bus_idx' sends to.

func GetBusVolumeDb

func GetBusVolumeDb(bus_idx Bus) Float.X

Returns the volume of the bus at index 'bus_idx' in dB.

func GetBusVolumeLinear

func GetBusVolumeLinear(bus_idx Bus) Float.X

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.DbToLinear on the result of GetBusVolumeDb.

func GetDriverName

func GetDriverName() string

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".

func GetInputDeviceList

func GetInputDeviceList() []string

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.

func GetInputMixRate

func GetInputMixRate() Float.X

Returns the sample rate at the input of the AudioServer.

func GetMixRate

func GetMixRate() Float.X

Returns the sample rate at the output of the AudioServer.

func GetOutputDeviceList

func GetOutputDeviceList() []string

Returns the names of all audio output devices detected on the system.

func GetOutputLatency

func GetOutputLatency() Float.X

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 GetOutputLatency every frame.

func GetTimeSinceLastMix

func GetTimeSinceLastMix() Float.X

Returns the relative time since the last mix occurred.

func GetTimeToNextMix

func GetTimeToNextMix() Float.X

Returns the relative time until the next mix occurs.

func InputDevice

func InputDevice() string

Name of the current device for audio input (see 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.

func IsBusBypassingEffects

func IsBusBypassingEffects(bus_idx Bus) bool

If true, the bus at index 'bus_idx' is bypassing effects.

func IsBusEffectEnabled

func IsBusEffectEnabled(bus_idx Bus, effect_idx Effect) bool

If true, the effect at index 'effect_idx' on the bus at index 'bus_idx' is enabled.

func IsBusMute

func IsBusMute(bus_idx Bus) bool

If true, the bus at index 'bus_idx' is muted.

func IsBusSolo

func IsBusSolo(bus_idx Bus) bool

If true, the bus at index 'bus_idx' is in solo mode.

func IsStreamRegisteredAsSample

func IsStreamRegisteredAsSample(stream AudioStream.Instance) bool

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 RegisterStreamAsSample.

func Lock

func Lock()

Locks the audio driver's main loop.

Note: Remember to unlock it afterwards.

func MoveBus

func MoveBus(index Bus, to_index Bus)

Moves the bus from index 'index' to index 'to_index'.

func OnBusLayoutChanged

func OnBusLayoutChanged(cb func(), flags ...Signal.Flags)

Emitted when an audio bus is added, deleted, or moved.

func OnBusRenamed

func OnBusRenamed(cb func(bus_index Bus, old_name string, new_name string), flags ...Signal.Flags)

Emitted when the audio bus at 'bus_index' is renamed from 'old_name' to 'new_name'.

func OutputDevice

func OutputDevice() string

Name of the current device for audio output (see 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".

func PlaybackSpeedScale

func PlaybackSpeedScale() Float.X

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.

func RegisterStreamAsSample

func RegisterStreamAsSample(stream AudioStream.Instance)

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.

func RemoveBus

func RemoveBus(index Bus)

Removes the bus at index 'index'.

func RemoveBusEffect

func RemoveBusEffect(bus_idx Bus, effect_idx Effect)

Removes the effect at index 'effect_idx' from the bus at index 'bus_idx'.

func SetBusBypassEffects

func SetBusBypassEffects(bus_idx Bus, enable bool)

If true, the bus at index 'bus_idx' is bypassing effects.

func SetBusCount

func SetBusCount(value int)

SetBusCount sets the property returned by [GetBusCount].

func SetBusEffectEnabled

func SetBusEffectEnabled(bus_idx Bus, effect_idx Effect, enabled bool)

If true, the effect at index 'effect_idx' on the bus at index 'bus_idx' is enabled.

func SetBusLayout

func SetBusLayout(bus_layout AudioBusLayout.Instance)

Overwrites the currently used AudioBusLayout.

func SetBusMute

func SetBusMute(bus_idx Bus, enable bool)

If true, the bus at index 'bus_idx' is muted.

func SetBusName

func SetBusName(bus_idx Bus, name string)

Sets the name of the bus at index 'bus_idx' to 'name'.

func SetBusSend

func SetBusSend(bus_idx Bus, send string)

Connects the output of the bus at 'bus_idx' to the bus named 'send'.

func SetBusSolo

func SetBusSolo(bus_idx Bus, enable bool)

If true, the bus at index 'bus_idx' is in solo mode.

func SetBusVolumeDb

func SetBusVolumeDb(bus_idx Bus, volume_db Float.X)

Sets the volume in decibels of the bus at index 'bus_idx' to 'volume_db'.

func SetBusVolumeLinear

func SetBusVolumeLinear(bus_idx Bus, volume_linear Float.X)

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 SetBusVolumeDb with the result of @GlobalScope.LinearToDb on a value.

func SetEnableTaggingUsedAudioStreams

func SetEnableTaggingUsedAudioStreams(enable bool)

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.

func SetInputDevice

func SetInputDevice(value string)

SetInputDevice sets the property returned by [GetInputDevice].

func SetOutputDevice

func SetOutputDevice(value string)

SetOutputDevice sets the property returned by [GetOutputDevice].

func SetPlaybackSpeedScale

func SetPlaybackSpeedScale(value Float.X)

SetPlaybackSpeedScale sets the property returned by [GetPlaybackSpeedScale].

func SwapBusEffects

func SwapBusEffects(bus_idx Bus, effect_idx Effect, by_effect_idx Effect)

Swaps the position of two effects in bus 'bus_idx'.

func Unlock

func Unlock()

Unlocks the audio driver's main loop. (After locking it, you should always unlock it.)

Types

type Bus

type Bus int

type Effect

type Effect int

type Extension

type Extension[T gdclass.Interface] struct{ gdclass.Extension[T, Instance] }

Extension can be embedded in a new struct to create an extension of this class. T should be the type that is embedding this Extension

func (*Extension[T]) AsObject

func (self *Extension[T]) AsObject() [1]gd.Object

type ID

type ID Object.ID

ID is a typed object ID (reference) to an instance of this class, use it to store references to objects with unknown lifetimes, as an ID will not panic on use if the underlying object has been destroyed.

func (ID) Instance

func (id ID) Instance() (Instance, bool)

type Instance

type Instance [1]gdclass.AudioServer

Instance of the class with convieniently typed arguments and results.

func (Instance) AsObject

func (self Instance) AsObject() [1]gd.Object

func (Instance) ID

func (self Instance) ID() ID

func (*Instance) SetObject

func (self *Instance) SetObject(obj [1]gd.Object) bool

func (Instance) Virtual

func (self Instance) Virtual(name string) reflect.Value

type PlaybackType

type PlaybackType int //gd:AudioServer.PlaybackType
const (
	// The playback will be considered of the type declared at [ProjectSettings] "audio/general/default_playback_type".
	//
	// [ProjectSettings]: https://pkg.go.dev/graphics.gd/classdb/ProjectSettings
	PlaybackTypeDefault PlaybackType = 0
	// Force the playback to be considered as a stream.
	PlaybackTypeStream PlaybackType = 1
	// 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: [AudioEffect]s are not supported when playback is considered as a sample.
	//
	// [AudioEffect]: https://pkg.go.dev/graphics.gd/classdb/AudioEffect
	PlaybackTypeSample PlaybackType = 2
	// Represents the size of the [PlaybackType] enum.
	PlaybackTypeMax PlaybackType = 3
)

type SpeakerMode

type SpeakerMode int //gd:AudioServer.SpeakerMode
const (
	// Two or fewer speakers were detected.
	SpeakerModeStereo SpeakerMode = 0
	// A 3.1 channel surround setup was detected.
	SpeakerSurround31 SpeakerMode = 1
	// A 5.1 channel surround setup was detected.
	SpeakerSurround51 SpeakerMode = 2
	// A 7.1 channel surround setup was detected.
	SpeakerSurround71 SpeakerMode = 3
)

func GetSpeakerMode

func GetSpeakerMode() SpeakerMode

Returns the speaker configuration.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL